Multiprocessing sidesteps the GIL by running separate processes, each with its own Python interpreter and its own GIL. That gives genuine parallelism across CPU cores — the right tool when the bottleneck is computation, not waiting.
ProcessPoolExecutor
The API mirrors the thread pool — just swap the executor — so switching from threads to processes is a one-line change:
from concurrent.futures import ProcessPoolExecutordef heavy(n):return sum(i * i for i in range(n)) # CPU-bound workwith ProcessPoolExecutor() as pool:results = list(pool.map(heavy, [10**6] * 4)) # runs across cores in parallel
The cost: no shared memory
Choosing your concurrency tool
| Work is… | Use |
|---|---|
| I/O-bound, many tasks | asyncio |
| I/O-bound, simple | threads |
| CPU-bound | multiprocessing |
Key takeaways
- 01Multiprocessing runs separate processes for true parallelism across cores.
- 02Each process has its own interpreter and GIL — ideal for CPU-bound work.
- 03ProcessPoolExecutor mirrors ThreadPoolExecutor — an easy swap.
- 04Data is pickled/copied between processes, so minimise what you pass.
- 05Rule of thumb: asyncio or threads for I/O-bound, multiprocessing for CPU-bound.
