Skip to main content
The asyncio module provides infrastructure for writing single-threaded concurrent code using coroutines, event loops, and async/await syntax.

Module Import

Basic Async/Await

Coroutines

Running Async Code

Concurrent Execution

gather() - Run Multiple Coroutines

create_task() - Create Tasks

Timeouts and Waiting

wait_for() - Timeout

wait() - Wait for Multiple Tasks

Async Iteration

Async Generators

Queues

Practical Examples

Concurrent HTTP Requests

Periodic Tasks

Use asyncio for I/O-bound concurrent operations like network requests and file I/O.
Don’t use asyncio for CPU-bound tasks - use multiprocessing instead.

threading

Thread-based parallelism

multiprocessing

Process-based parallelism