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 →
Related concepts
- awaitableproduces · An awaitable is a Python object that can be used with the await expression to suspend a coroutine until the asynchronous operation completes and produce its result.
- taskuses · A task is a defined unit of work, computation, or action directed toward a result or objective.
- api calluses · An API call is a programmatic request or invocation through an application programming interface to access data or invoke an operation.
- futureimplements · A future is an abstraction representing an asynchronous computation or its result, which may not be complete or available yet.
- coroutineuses · A coroutine is a computation that can suspend and later resume execution while retaining its state, enabling cooperative transfer of control.
- asyncio.create_taskalternative to · asyncio.create_task is a Python asyncio function that schedules a coroutine to run as a Task on an event loop and returns that Task.
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.


