本文整理匯總了Python中pulsar.Future.set_exception方法的典型用法代碼示例。如果您正苦於以下問題:Python Future.set_exception方法的具體用法?Python Future.set_exception怎麽用?Python Future.set_exception使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pulsar.Future
的用法示例。
在下文中一共展示了Future.set_exception方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_ping_pong_monitor
# 需要導入模塊: from pulsar import Future [as 別名]
# 或者: from pulsar.Future import set_exception [as 別名]
def test_ping_pong_monitor(self):
value = yield 3
self.assertEqual(value, 3)
try:
future = Future()
future.set_exception(ValueError('test'))
yield future
except ValueError:
pass
pong = yield send('monitor', 'ping')
self.assertEqual(pong, 'pong')
示例2: check_twisted
# 需要導入模塊: from pulsar import Future [as 別名]
# 或者: from pulsar.Future import set_exception [as 別名]
def check_twisted(deferred, loop):
"""Binding for twisted.
Added to pulsar asynchronous engine via the :func:`.add_async_binding`
function.
"""
if isinstance(deferred, Deferred):
future = Future(loop=loop)
deferred.addCallbacks(future.set_result, lambda failure: future.set_exception(failure.value))
return future
示例3: _
# 需要導入模塊: from pulsar import Future [as 別名]
# 或者: from pulsar.Future import set_exception [as 別名]
def _(*args, **kwargs):
res = callable(*args, **kwargs)
if isinstance(res, types.GeneratorType):
res = _inlineCallbacks(None, res, Deferred())
if isinstance(res, Deferred):
future = Future()
res.addCallbacks(
future.set_result,
lambda failure: future.set_exception(failure.value))
future._deferred = res
return future
else:
raise TypeError(
"Callable %r should return a generator or a twisted Deferred"
% callable)