python - asyncio.wait和asyncio.gather的区别?
天蓬老师
天蓬老师 2017-04-18 10:26:40
0
2
910

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


天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
巴扎黑

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.

PHPzhong

RTFM......

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template