刚学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))
巴扎黑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.