Asyncio.gather vs asyncio.wait

前端 未结 5 2011
小鲜肉
小鲜肉 2020-12-04 05:11

asyncio.gather and asyncio.wait seem to have similar uses: I have a bunch of async things that I want to execute/wait for (not necessarily waiting for one to finish before t

5条回答
  •  难免孤独
    2020-12-04 05:48

    I also noticed that you can provide a group of coroutines in wait() by simply specifying the list:

    result=loop.run_until_complete(asyncio.wait([
            say('first hello', 2),
            say('second hello', 1),
            say('third hello', 4)
        ]))
    

    Whereas grouping in gather() is done by just specifying multiple coroutines:

    result=loop.run_until_complete(asyncio.gather(
            say('first hello', 2),
            say('second hello', 1),
            say('third hello', 4)
        ))
    

提交回复
热议问题