asyncio.gather和asyncio.wait似乎有相似的用途:我有一堆想要执行/等待的异步事务(不一定要等到一个完成后才开始下一个)。它们使用不同的语法,在一些细节上也不同,但在我看来,有两个函数在功能上有如此巨大的重叠,这对我来说是非常不自然的。我遗漏了什么?
发布于 2018-01-31 00:31:08
我还注意到,您可以通过简单地指定列表来在wait()中提供一组协程:
result=loop.run_until_complete(asyncio.wait([
say('first hello', 2),
say('second hello', 1),
say('third hello', 4)
]))而gather()中的分组是通过指定多个协程来完成的:
result=loop.run_until_complete(asyncio.gather(
say('first hello', 2),
say('second hello', 1),
say('third hello', 4)
))https://stackoverflow.com/questions/42231161
复制相似问题