Skip to content

concurrency

In programming, concurrency refers to the ability of a program to manage multiple tasks simultaneously. This can significantly improve the efficiency and performance of your programs, especially when dealing with I/O-bound tasks.

In Python, you can achieve concurrency through several mechanisms, such as threads, asyncio, and multiprocessing. While threads and asyncio allow for concurrent execution in a single process, multiprocessing enables you to run concurrent tasks across multiple processes, taking advantage of multiple CPU cores.

Newer Python versions also let threads use multiple cores, either through the free-threaded build (Python 3.13+) or by running them in separate interpreters with the concurrent.interpreters module (Python 3.14+).

Example

Here’s a simple example using Python’s asyncio module to run two tasks concurrently:

Language: Python
>>> import asyncio

>>> async def task1():
...     for i in range(5):
...         print(f'Task 1 - Iteration {i}')
...         await asyncio.sleep(1)
...

>>> async def task2():
...     for i in range(5):
...         print(f'Task 2 - Iteration {i}')
...         await asyncio.sleep(1)
...

>>> async def main():
...     await asyncio.gather(task1(), task2())
...

>>> asyncio.run(main())
Task 1 - Iteration 0
Task 2 - Iteration 0
Task 1 - Iteration 1
Task 2 - Iteration 1
Task 1 - Iteration 2
Task 2 - Iteration 2
Task 1 - Iteration 3
Task 2 - Iteration 3
Task 1 - Iteration 4
Task 2 - Iteration 4

In this example, task1() and task2() run concurrently, allowing both tasks to perform their operations without blocking each other.

Async IO in Python: A Complete Walkthrough

Course

Hands-On Python 3 Concurrency With the asyncio Module

Learn how to speed up your Python 3 programs using concurrency and the asyncio module in the standard library. See step-by-step how to leverage concurrency and parallelism in your own programs, all the way to building a complete HTTP downloader example app using asyncio and aiohttp.

advanced python

For additional information on related topics, take a look at the following resources:

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Sept. 27, 2026