首页  >  问答  >  正文

python - asyncio.wait和asyncio.gather的区别?

刚学PYTHON的协程,我想请教下,这两段代码执行起来有什么区别呢?

tasks = [asyncio.ensure_future(task(i)) for i in range(0,300)]
loop.run_until_complete(asyncio.gather(*tasks))

tasks = [task(i) for i in range(0,300)]
loop.run_until_complete(asyncio.wait(tasks))


天蓬老师天蓬老师2741 天前878

全部回复(2)我来回复

  • 巴扎黑

    巴扎黑2017-04-18 10:28:40

    看文档就知道了,这两段代码的效果相同。但是 wait 和 gather 的返回值不一样,wait 也可以在第一个 future 完全或者出错时就返回。

    回复
    0
  • PHPz

    PHPz2017-04-18 10:28:40

    RTFM......

    回复
    0
  • 取消回复