python - asyncio.await失败,并出现TypeError : cannot unpack non-iterable coroutine object

标签 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

最佳答案

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

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

关于python - asyncio.await失败,并出现TypeError : cannot unpack non-iterable coroutine object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51527364/

相关文章:

python - 计数矢量器 : Vocabulary wasn't fitted

Python 3.5+ : How to dynamically import a module given the full file path (in the presence of implicit sibling imports)?

python - 使用 aiohttp.ClientSession.get 时如何模拟协程 json()

Python 异步队列未更新

python 的 asyncio 在 2 个协程之间交换数据 - 其中一个执行同步和 CPU 密集型代码

python - Python 中的曲线拟合不适合我的曲线

python - 退出守护进程的问题

python - 如何在不阻塞事件循环的情况下迭代一个大列表

python - Python 中的 str(time.time()) 时数据被截断

Python 和信号处理程序