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


Python Fiber.current方法代码示例

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


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

示例1: switch

# 需要导入模块: from fibers import Fiber [as 别名]
# 或者: from fibers.Fiber import current [as 别名]
 def switch(self):
     if not self._started:
         self.run()
         return
     current = Fiber.current()
     assert current is not self.task, 'Cannot switch to MAIN from MAIN'
     try:
         if self.task.parent is not current:
             current.parent = self.task
     except ValueError:
         pass  # gets raised if there is a Fiber parent cycle
     return self.task.switch()
开发者ID:crudbug,项目名称:evergreen,代码行数:14,代码来源:loop.py

示例2: run

# 需要导入模块: from fibers import Fiber [as 别名]
# 或者: from fibers.Fiber import current [as 别名]
 def run(self, mode=RUN_DEFAULT):
     if Fiber.current() is not self.task.parent:
         raise RuntimeError('run() can only be called from MAIN fiber')
     if not self.task.is_alive():
         raise RuntimeError('event loop has already ended')
     if self._started:
         raise RuntimeError('event loop was already started')
     self._started = True
     self._running = True
     self._run_mode = mode
     try:
         self.task.switch()
     finally:
         self._running = False
开发者ID:crudbug,项目名称:evergreen,代码行数:16,代码来源:loop.py

示例3: sleep

# 需要导入模块: from fibers import Fiber [as 别名]
# 或者: from fibers.Fiber import current [as 别名]
def sleep(seconds=0):
    """Yield control to another eligible coroutine until at least *seconds* have
    elapsed.

    *seconds* may be specified as an integer, or a float if fractional seconds
    are desired.
    """
    loop = evergreen.current.loop
    current = Fiber.current()
    assert loop.task is not current
    timer = loop.call_later(seconds, current.switch)
    try:
        loop.switch()
    finally:
        timer.cancel()
开发者ID:crudbug,项目名称:evergreen,代码行数:17,代码来源:tasks.py

示例4: _handle_error

# 需要导入模块: from fibers import Fiber [as 别名]
# 或者: from fibers.Fiber import current [as 别名]
 def _handle_error(self, typ, value, tb):
     if not issubclass(typ, SystemExit):
         traceback.print_exception(typ, value, tb)
     if issubclass(typ, (KeyboardInterrupt, SystemExit, SystemError)):
         assert Fiber.current() is self.task
         self.task.parent.throw(typ, value, tb)
开发者ID:crudbug,项目名称:evergreen,代码行数:8,代码来源:loop.py


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