代码之家  ›  专栏  ›  技术社区  ›  Messa

asyncio.await失败,返回TypeError:无法解压缩不可iterable coroutine对象

  •  1
  • Messa  · 技术社区  · 6 年前

    我有这个密码:

    done, pending = asyncio.wait(
        [a, b],
        return_when=asyncio.FIRST_COMPLETED)
    

    但它失败了:

    Traceback (most recent call last):
      ...
      File "/.../api.py", line 83, in websockets_handler
        return_when=asyncio.FIRST_COMPLETED)
    TypeError: cannot unpack non-iterable coroutine object
    
    1 回复  |  直到 6 年前
        1
  •  3
  •   Messa    6 年前

    嗯,应该有 await 在前面 asyncio.wait :)

    done, pending = await asyncio.wait(
        [a, b],
        return_when=asyncio.FIRST_COMPLETED)