python
runtime_error
ai_generated
true
RuntimeWarning: coroutine 'fetch_data' was never awaited
ID: python/coroutine-never-awaited
80%Fix Rate
90%Confidence
0Evidence
2024-02-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
| 3.12 | active | — | — | — |
Root Cause
A coroutine function was called without await or asyncio.create_task, so the coroutine object was created and garbage collected without running.
generic中文
调用了一个协程函数但没有 await 或 asyncio.create_task,因此创建了协程对象并在未运行的情况下被垃圾回收。
Workarounds
-
95% success
Await the coroutine in an async context: async def main(): data = await fetch_data() -
90% success
If you intentionally want fire-and-forget, schedule it: asyncio.create_task(fetch_data())
-
88% success
Enable -W error::RuntimeWarning in tests to catch this at CI time.
Dead Ends
Common approaches that don't work:
-
90% fail
Hides the symptom; the async work silently never runs.
-
85% fail
Raises 'asyncio.run() cannot be called from a running event loop'.
-
70% fail
Breaks other callers and loses concurrency.