Skip to main content
Albero Academy

Multiprocessing

Use multiple CPU cores for genuine parallel computation.

Advanced Python10 min

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:

use all your cores
from concurrent.futures import ProcessPoolExecutor
def heavy(n):
return sum(i * i for i in range(n)) # CPU-bound work
with 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 tasksasyncio
I/O-bound, simplethreads
CPU-boundmultiprocessing

Key takeaways

  1. 01Multiprocessing runs separate processes for true parallelism across cores.
  2. 02Each process has its own interpreter and GIL — ideal for CPU-bound work.
  3. 03ProcessPoolExecutor mirrors ThreadPoolExecutor — an easy swap.
  4. 04Data is pickled/copied between processes, so minimise what you pass.
  5. 05Rule of thumb: asyncio or threads for I/O-bound, multiprocessing for CPU-bound.

Finished this chapter?

Mark it complete to track your progress through Python.