python
type_error
ai_generated
true
TypeError: An asyncio.Future, a coroutine or an awaitable is required
ID: python/asyncio-gather-return-exceptions
80%Fix Rate
84%Confidence
0Evidence
2024-05-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.7 | active | — | — | — |
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
Root Cause
Passing non-awaitable objects (e.g., a list of results) to asyncio.gather() or asyncio.wait()
generic中文
向asyncio.gather()或asyncio.wait()传递不可等待的对象(如结果列表)。
Workarounds
-
100% success
await asyncio.gather(coro1(), coro2())
-
95% success
tasks = [asyncio.create_task(coro()) for coro in coros]; await asyncio.gather(*tasks)
Dead Ends
Common approaches that don't work:
-
90% fail
ensure_future() expects coroutines or futures, not plain values.
-
90% fail
create_task() also requires coroutines, not arbitrary objects.