python type_error ai_generated true

类型错误:需要asyncio.Future、协程或可等待对象

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

ID: python/asyncio-gather-return-exceptions

其他格式: JSON · Markdown 中文 · English
80%修复率
84%置信度
0证据数
2024-05-01首次发现

版本兼容性

版本状态引入弃用备注
3.7 active
3.8 active
3.9 active

根因分析

向asyncio.gather()或asyncio.wait()传递不可等待的对象(如结果列表)。

English

Passing non-awaitable objects (e.g., a list of results) to asyncio.gather() or asyncio.wait()

generic

解决方案

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

无效尝试

常见但无效的做法:

  1. 90% 失败

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

  2. 90% 失败

    create_task() also requires coroutines, not arbitrary objects.