【发布时间】:2018-08-22 00:06:44
【问题描述】:
如果我有以下代码示例
async def coro():
# Cancelled error could be raised here
await asyncio.sleep(1)
# Or here
await asyncio.shield(
another_coro()
)
# Or here
async def wait_on_it(loop):
f = loop.create_task(coro())
# Pretend f may or may not happen, I just sleep in this example
await asyncio.sleep(1)
if not f.done():
f.cancel() # Will raise CancelledError when some await finishes in coro()
如何确定屏蔽任务是否实际运行?如果屏蔽任务确实运行,我有必须运行的重要逻辑。也许屏蔽那个功能不是正确的方法?
【问题讨论】: