本文整理汇总了Python中pulsar.Future.result方法的典型用法代码示例。如果您正苦于以下问题:Python Future.result方法的具体用法?Python Future.result怎么用?Python Future.result使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pulsar.Future
的用法示例。
在下文中一共展示了Future.result方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_coroutine1
# 需要导入模块: from pulsar import Future [as 别名]
# 或者: from pulsar.Future import result [as 别名]
def test_coroutine1(self):
loop = get_event_loop()
d1 = Future()
loop.call_later(0.2, d1.set_result, 1)
a = yield c_summation(d1)
self.assertEqual(a, 3)
self.assertEqual(d1.result(), 1)
示例2: wait_fd
# 需要导入模块: from pulsar import Future [as 别名]
# 或者: from pulsar.Future import result [as 别名]
def wait_fd(fd, read=True):
'''Wait for an event on file descriptor ``fd``.
:param fd: file descriptor
:param read=True: wait for a read event if ``True``, otherwise a wait
for write event.
This function must be invoked from a coroutine with parent, therefore
invoking it from the main greenlet will raise an exception.
Check how this function is used in the :func:`.psycopg2_wait_callback`
function.
'''
current = greenlet.getcurrent()
parent = current.parent
assert parent, '"wait_fd" must be called by greenlet with a parent'
try:
fileno = fd.fileno()
except AttributeError:
fileno = fd
loop = get_event_loop()
future = Future(loop=loop)
# When the event on fd occurs switch back to the current greenlet
if read:
loop.add_reader(fileno, _done_wait_fd, fileno, future, read)
else:
loop.add_writer(fileno, _done_wait_fd, fileno, future, read)
# switch back to parent greenlet
parent.switch(future)
return future.result()
示例3: test_call_later
# 需要导入模块: from pulsar import Future [as 别名]
# 或者: from pulsar.Future import result [as 别名]
def test_call_later(self):
ioloop = get_event_loop()
tid = yield loop_thread_id(ioloop)
d = Future()
timeout1 = ioloop.call_later(
20, lambda: d.set_result(current_thread().ident))
timeout2 = ioloop.call_later(
10, lambda: d.set_result(current_thread().ident))
# lets wake the ioloop
self.assertTrue(has_callback(ioloop, timeout1))
self.assertTrue(has_callback(ioloop, timeout2))
timeout1.cancel()
timeout2.cancel()
self.assertTrue(timeout1._cancelled)
self.assertTrue(timeout2._cancelled)
timeout1 = ioloop.call_later(
0.1, lambda: d.set_result(current_thread().ident))
yield d
self.assertTrue(d.done())
self.assertEqual(d.result(), tid)
self.assertFalse(has_callback(ioloop, timeout1))