python
runtime_error
ai_generated
true
asyncio异常:任务异常从未被检索
asyncio.exceptions.CancelledError: Task exception was never retrieved
ID: python/asyncio-task-exception-silent
80%修复率
86%置信度
0证据数
2025-02-14首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.7 | active | — | — | — |
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
根因分析
任务引发异常,但异常从未被等待或检索,导致静默失败。
English
A task raises an exception but the exception is never awaited or retrieved, leading to silent failures.
解决方案
-
90% 成功率
task.add_done_callback(lambda t: t.exception() if not t.cancelled() else None)
-
95% 成功率
try: await task except Exception as e: print(e)
无效尝试
常见但无效的做法:
-
90% 失败
The exception is lost, making debugging difficult.
-
60% 失败
If the task is not done, it may block or raise.