python type_error ai_generated true

TypeError: An asyncio.Future, a coroutine or an awaitable is required

ID: python/asyncio-gather-return-exceptions

Also available as: JSON · Markdown · 中文
80%Fix Rate
84%Confidence
0Evidence
2024-05-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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

  1. 100% success
    await asyncio.gather(coro1(), coro2())
  2. 95% success
    tasks = [asyncio.create_task(coro()) for coro in coros]; await asyncio.gather(*tasks)

Dead Ends

Common approaches that don't work:

  1. 90% fail

    ensure_future() expects coroutines or futures, not plain values.

  2. 90% fail

    create_task() also requires coroutines, not arbitrary objects.