python
runtime_error
ai_generated
true
RuntimeError: cannot reuse already awaited coroutine
ID: python/asyncio-run-coroutine-twice
80%Fix Rate
90%Confidence
0Evidence
2024-12-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.7 | active | — | — | — |
| 3.8 | active | — | — | — |
Root Cause
Attempting to await the same coroutine object more than once, which is not allowed in asyncio.
generic中文
尝试多次等待同一个协程对象,这在asyncio中是不允许的。
Workarounds
-
100% success
async def my_coro(): pass; await my_coro(); await my_coro()
-
95% success
task = asyncio.create_task(my_coro()); await task; task2 = asyncio.create_task(my_coro()); await task2
Dead Ends
Common approaches that don't work:
-
100% fail
The coroutine is already exhausted; you must create a new coroutine.
-
90% fail
Coroutines are not meant to be manually driven; it's complex and error-prone.