Asyncio.gather
asyncio.gather is a Python asyncio function that runs multiple awaitable objects concurrently, waits for them to complete, and collects their results.
Python Concurrency with asyncio
asyncio.gather is an asyncio function that concurrently schedules awaitables and completes after all of them finish, optionally returning exceptions as results.
- How it is used
- Coordinates groups of asynchronous operations when later processing should wait for every operation to complete.
- How deep it goes
- Explains awaitable wrapping, group completion, result collection, and exception modes, but defers lower-level task scheduling internals.
- Examples
- Uses concurrent HTTP status requests, delayed awaitables, invalid URLs, thread-pool work, encrypted subprocesses, and a custom task runner.
- What you can do after
- Apply it via asyncio to launch awaitables concurrently, collect group results, and choose an exception-handling strategy.
Read how Python Concurrency with asyncio explains asyncio.gather →
AI Agents in Action, Second Edition
A Python asyncio function that concurrently schedules awaitable objects and returns their results together.
- How it is used
- Speeds repetitive task loops by processing independent work items concurrently.
- How deep it goes
- Provides an implementation pattern and comparison exercise, but defers detailed API mechanics and concurrency internals.
- Examples
- Uses five text-transformation tasks, a batch size of three, and sequential-versus-parallel timing and completion-rate comparisons.
- What you can do after
- Apply it via Python asyncio to parallelize independent task-loop items and evaluate speedup against sequential processing.
Read how AI Agents in Action, Second Edition explains asyncio.gather →
Building LLM Applications with DSPy
asyncio.gather runs multiple awaitables concurrently and collects their results.
- How it is used
- Coordinates multiple coroutines concurrently and collects their return values.
- How deep it goes
- Explains task creation, completion, result ordering, and elapsed-time savings.
- Examples
- Times two coroutines that sleep for five and three seconds, then prints their ordered results.
- What you can do after
- Apply asyncio.gather to run coroutines concurrently and capture their results in input order.
Read how Building LLM Applications with DSPy explains asyncio.gather →
Also covered in
Related concepts
- api calluses · An API call is a programmatic request or invocation sent through an application programming interface to retrieve data or invoke an exposed operation.
- awaitableproduces · An awaitable is a Python object that can be used in an await expression to obtain the result of an asynchronous computation.
- futureimplements · A future is an abstraction representing an asynchronous computation’s result, which may become available later and may be pending or complete.
- taskuses · A task is a discrete unit of work, activity, or computation to be performed or completed.
- coroutineuses · A coroutine is a computation that can suspend and later resume execution while retaining its state, enabling cooperative transfer of control.
- asyncio.as_completedcontrasts with · asyncio.as_completed is an asyncio function that yields awaitables producing results in the order their underlying operations complete.
Questions about asyncio.gather
What is asyncio.gather?
asyncio.gather is a Python asyncio function that runs multiple awaitable objects concurrently, waits for them to complete, and collects their results.
Which Manning books explain asyncio.gather?
Python Concurrency with asyncio, AI Agents in Action, Second Edition and Building LLM Applications with DSPy.
What is the difference between asyncio.gather and asyncio.as_completed?
asyncio.gather is a Python asyncio function that runs multiple awaitable objects concurrently, waits for them to complete, and collects their results. asyncio.as_completed is an asyncio function that yields awaitables producing results in the order their underlying operations complete.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


