def __await__(self):
def exec_when_ready():
event.wait()
coro.send(None)
if not self.exited:
raise RuntimeError('attempted to "await" in a worker thread')
if self.exited:
# This is run in the worker thread
yield
else:
# This is run in the event loop thread
previous_frame = inspect.currentframe().f_back
coro = next(obj for obj in gc.get_referrers(previous_frame.f_code)
if inspect.iscoroutine(obj) and obj.cr_frame is previous_frame)
event = Event()
loop = get_event_loop()
future = loop.run_in_executor(self.executor, exec_when_ready)
next(future.__await__()) # Make the future think it's being awaited on
loop.call_soon(event.set)
yield future
评论列表
文章目录