python
runtime_error
ai_generated
true
RuntimeWarning: 协程 'fetch' 从未被 await
RuntimeWarning: coroutine 'fetch' was never awaited
ID: python/asyncio-coroutine-never-awaited
80%修复率
89%置信度
0证据数
2024-04-08首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.8+ | active | — | — | — |
| 3.9+ | active | — | — | — |
| 3.10+ | active | — | — | — |
| 3.11+ | active | — | — | — |
| 3.12+ | active | — | — | — |
根因分析
调用了协程函数但返回的协程对象既未 await 也未调度,导致函数体从未执行。
English
A coroutine function was called but the returned coroutine object was not awaited or scheduled, so the body never executed.
解决方案
-
97% 成功率
await fetch(url) # or asyncio.create_task(fetch(url))
-
85% 成功率
PYTHONASYNCIODEBUG=1 python app.py # or in code: loop = asyncio.get_running_loop() loop.set_debug(True)
无效尝试
常见但无效的做法:
-
90% 失败
Hides the warning but the coroutine still never runs; business logic silently missing.
-
85% 失败
Both calls produce unawaited coroutine objects; neither executes.