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:
>>> 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.
Related Resources
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.
For additional information on related topics, take a look at the following resources:
- Speed Up Your Python Program With Concurrency (Tutorial)
- Speed Up Python With Concurrency (Course)
- Python 3.14 Release Candidate Lands: Faster Code, Smarter Concurrency (Tutorial)
- Python's asyncio: A Hands-On Walkthrough (Tutorial)
- An Intro to Threading in Python (Tutorial)
- Understanding Python's Global Interpreter Lock (GIL) (Course)
- Threading in Python (Course)
- Python Concurrency (Quiz)
- Python's asyncio: A Hands-On Walkthrough (Quiz)
- Python Threading (Quiz)
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