小编com*_*rer的帖子

在创建后存储asyncio任务时,来自任务的异常会被静音

我正在为项目使用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()阻止异常执行任何操作.

有人能否对这种情况有所了解?我需要有一种方法来捕获当前项目中的异常.

python python-asyncio

6
推荐指数
1
解决办法
834
查看次数

标签 统计

python ×1

python-asyncio ×1