asyncio.await失败,并出现TypeError:无法解包不可迭代的协程对象

时间:2018-07-25 20:43:46

标签: python python-asyncio

我有此代码:

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 个答案:

答案 0 :(得分:2)

好吧,await前面应该有asyncio.wait:)

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