本文整理汇总了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()
示例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
示例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()
示例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)