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


Python Future.result方法代码示例

本文整理汇总了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)
开发者ID:axisofentropy,项目名称:pulsar,代码行数:9,代码来源:coro.py

示例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()
开发者ID:JinsongBian,项目名称:pulsar,代码行数:31,代码来源:__init__.py

示例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))
开发者ID:JinsongBian,项目名称:pulsar,代码行数:23,代码来源:eventloop.py


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