当前位置: 首页>>代码示例>>Python>>正文


Python Future.add_done_callback方法代码示例

本文整理汇总了Python中hazelcast.future.Future.add_done_callback方法的典型用法代码示例。如果您正苦于以下问题:Python Future.add_done_callback方法的具体用法?Python Future.add_done_callback怎么用?Python Future.add_done_callback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hazelcast.future.Future的用法示例。


在下文中一共展示了Future.add_done_callback方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_callback_throws_exception

# 需要导入模块: from hazelcast.future import Future [as 别名]
# 或者: from hazelcast.future.Future import add_done_callback [as 别名]
    def test_callback_throws_exception(self):
        f = Future()

        def invalid_func():
            raise RuntimeError("error!")

        f.add_done_callback(invalid_func)
        f.set_result("done")  # should not throw exception
开发者ID:hazelcast,项目名称:hazelcast-python-client,代码行数:10,代码来源:future_test.py

示例2: test_add_callback_after_completion_with_success

# 需要导入模块: from hazelcast.future import Future [as 别名]
# 或者: from hazelcast.future.Future import add_done_callback [as 别名]
    def test_add_callback_after_completion_with_success(self):
        f = Future()
        f.set_result("done")

        counter = [0]

        def callback(future):
            counter[0] += 1
            self.assertEqual(future.result(), "done")

        f.add_done_callback(callback)
        self.assertEqual(counter[0], 1)
开发者ID:hazelcast,项目名称:hazelcast-python-client,代码行数:14,代码来源:future_test.py

示例3: test_add_callback_after_completion_with_error

# 需要导入模块: from hazelcast.future import Future [as 别名]
# 或者: from hazelcast.future.Future import add_done_callback [as 别名]
    def test_add_callback_after_completion_with_error(self):
        f = Future()
        error = RuntimeError("error")
        f.set_exception(error, None)

        counter = [0]

        def callback(future):
            counter[0] += 1
            self.assertEqual(future.exception(), error)

        f.add_done_callback(callback)
        self.assertEqual(counter[0], 1)
开发者ID:hazelcast,项目名称:hazelcast-python-client,代码行数:15,代码来源:future_test.py

示例4: test_add_callback_with_success

# 需要导入模块: from hazelcast.future import Future [as 别名]
# 或者: from hazelcast.future.Future import add_done_callback [as 别名]
    def test_add_callback_with_success(self):
        f = Future()
        e = Event()

        def set_result():
            f.set_result("done")

        def callback(future):
            self.assertEqual(future.result(), "done")
            e.set()

        f.add_done_callback(callback)

        Thread(target=set_result).start()

        self.assertTrue(e.wait(timeout=5))
开发者ID:hazelcast,项目名称:hazelcast-python-client,代码行数:18,代码来源:future_test.py

示例5: test_callback_called_exactly_once_when_exception

# 需要导入模块: from hazelcast.future import Future [as 别名]
# 或者: from hazelcast.future.Future import add_done_callback [as 别名]
    def test_callback_called_exactly_once_when_exception(self):
        for _ in xrange(0, 10000):
            f = Future()

            def set_exception():
                f.set_exception(RuntimeError("error"))

            t = Thread(target=set_exception)
            t.start()

            i = [0]

            def callback(c):
                i[0] += 1

            f.add_done_callback(callback)
            t.join()
            self.assertEqual(i[0], 1)
开发者ID:hazelcast,项目名称:hazelcast-python-client,代码行数:20,代码来源:future_test.py

示例6: test_callback_called_exactly_once

# 需要导入模块: from hazelcast.future import Future [as 别名]
# 或者: from hazelcast.future.Future import add_done_callback [as 别名]
    def test_callback_called_exactly_once(self):
        for _ in xrange(0, 10000):
            f = Future()

            def set_result():
                f.set_result("done")

            t = Thread(target=set_result)
            t.start()

            i = [0]

            def callback(c):
                i[0] += 1

            f.add_done_callback(callback)
            t.join()
            self.assertEqual(i[0], 1)
开发者ID:hazelcast,项目名称:hazelcast-python-client,代码行数:20,代码来源:future_test.py

示例7: test_add_callback_with_failure

# 需要导入模块: from hazelcast.future import Future [as 别名]
# 或者: from hazelcast.future.Future import add_done_callback [as 别名]
    def test_add_callback_with_failure(self):
        f = Future()
        e = Event()
        exc = []

        def set_exception():
            map = {}
            try:
                a = map["invalid_key"]
            except KeyError as e:
                exc.append(sys.exc_info())
                f.set_exception(e, sys.exc_info()[2])

        def callback(future):
            exc_info = exc[0]
            self.assertEqual(exc_info[1], future.exception())
            self.assertEqual(exc_info[2], future.traceback())
            e.set()

        f.add_done_callback(callback)

        Thread(target=set_exception).start()

        self.assertTrue(e.wait(timeout=5))
开发者ID:hazelcast,项目名称:hazelcast-python-client,代码行数:26,代码来源:future_test.py


注:本文中的hazelcast.future.Future.add_done_callback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。