search

Home  >  Q&A  >  body text

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))


天蓬老师天蓬老师2786 days ago911

reply all(2)I'll reply

  • 巴扎黑

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

    Just look at the documentation and you will know that these two pieces of code have the same effect. However, the return values ​​of wait and gather are different. Wait can also return when the first future is complete or an error occurs.

    reply
    0
  • PHPz

    PHPz2017-04-18 10:28:40

    RTFM......

    reply
    0
  • Cancelreply