Python 3.4+Async programmingfunction
asyncio.gather()
concurrency
Runs several coroutines concurrently and waits until all of them finish. Returns the list of results.
Syntax
results = await asyncio.gather(coro1, coro2, ...)
Results come back in argument order, never in completion order. With the default return_exceptions=False the first failure propagates at once, yet the remaining coroutines are not cancelled and keep running in the background — that is where stray tasks and shutdown warnings come from; return_exceptions=True instead places each exception into the result list. On Python 3.11+ asyncio.TaskGroup is usually the better fit when you want the whole group cancelled on failure.
Examples
import asyncio
async def fetch(n):
await asyncio.sleep(0)
return n ** 2
async def main():
res = await asyncio.gather(fetch(2), fetch(3), fetch(4))
print(res) # → [4, 9, 16] — порядок аргументов, а не завершения
asyncio.run(main())
See also
Open in the full glossarydocs.python.orgReport an inaccuracy