本文整理汇总了Python中hazelcast.future.Future.set_exception方法的典型用法代码示例。如果您正苦于以下问题:Python Future.set_exception方法的具体用法?Python Future.set_exception怎么用?Python Future.set_exception使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hazelcast.future.Future
的用法示例。
在下文中一共展示了Future.set_exception方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Invocation
# 需要导入模块: from hazelcast.future import Future [as 别名]
# 或者: from hazelcast.future.Future import set_exception [as 别名]
class Invocation(object):
sent_connection = None
timer = None
def __init__(self, request, partition_id=-1, address=None, connection=None, timeout=INVOCATION_TIMEOUT):
self._event = threading.Event()
self.timeout = timeout + time.time()
self.address = address
self.connection = connection
self.partition_id = partition_id
self.request = request
self.future = Future()
def has_connection(self):
return self.connection is not None
def has_partition_id(self):
return self.partition_id >= 0
def has_address(self):
return self.address is not None
def set_response(self, response):
if self.timer:
self.timer.cancel()
self.future.set_result(response)
def set_exception(self, exception, traceback=None):
if self.timer:
self.timer.cancel()
self.future.set_exception(exception, traceback)
def on_timeout(self):
self.set_exception(TimeoutError("Request timed out after %d seconds." % INVOCATION_TIMEOUT))
示例2: test_continue_with_on_failure
# 需要导入模块: from hazelcast.future import Future [as 别名]
# 或者: from hazelcast.future.Future import set_exception [as 别名]
def test_continue_with_on_failure(self):
f = Future()
f.set_exception(RuntimeError("error"))
def continuation(future):
if future.is_success():
return 0
else:
return 1
result = f.continue_with(continuation).result()
self.assertEqual(1, result)
示例3: test_add_callback_after_completion_with_error
# 需要导入模块: from hazelcast.future import Future [as 别名]
# 或者: from hazelcast.future.Future import set_exception [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)
示例4: test_result_raises_exception_with_traceback
# 需要导入模块: from hazelcast.future import Future [as 别名]
# 或者: from hazelcast.future.Future import set_exception [as 别名]
def test_result_raises_exception_with_traceback(self):
f = Future()
exc_info = None
try:
{}["invalid_key"]
except KeyError as e:
exc_info = sys.exc_info()
f.set_exception(e, sys.exc_info()[2])
try:
f.result()
self.fail("Future.result() should raise exception")
except:
info = sys.exc_info()
self.assertEqual(info[1], exc_info[1])
original_tb = traceback.extract_tb(exc_info[2])
# shift traceback by one to discard the last frame
actual_tb = traceback.extract_tb(info[2])[1:]
self.assertEqual(original_tb, actual_tb)
示例5: test_set_exception_with_non_exception
# 需要导入模块: from hazelcast.future import Future [as 别名]
# 或者: from hazelcast.future.Future import set_exception [as 别名]
def test_set_exception_with_non_exception(self):
f = Future()
with self.assertRaises(RuntimeError):
f.set_exception("non-exception")