我正在为项目使用asyncio,并遇到了这种奇怪的行为.
import asyncio
def schedule_something():
global f
tsk = asyncio.async(do_something())
f = tsk #If this line is commented out, exceptions can be heard.
@asyncio.coroutine
def do_something():
raise Exception()
loop = asyncio.get_event_loop()
loop.call_soon(schedule_something)
loop.run_forever()
loop.close()
Run Code Online (Sandbox Code Playgroud)
出于某种原因,在调用时存储生成的任务会asyncio.async()阻止异常执行任何操作.
有人能否对这种情况有所了解?我需要有一种方法来捕获当前项目中的异常.