Python multiprocessing vs threading
Threads share one process and the GIL; multiprocessing spawns processes so CPU work can use more cores.
Published here , updated · 7 sources · Resume reading
Threading shares one process; multiprocessing starts more processes. CPython's GIL keeps that difference painful for CPU-bound Python, so pick the module that matches the bottleneck [1] [2] [3]. Pair with Python GIL: why threads are not truly parallel and concurrency vs parallelism.
Quick start: two threads, two processes
Save as mp_thread_demo.py and run with Python 3:
import threading
import time
def wait_label(name):
time.sleep(0.2)
print(name)
t0 = time.time()
t1 = threading.Thread(target=wait_label, args=("a",))
t2 = threading.Thread(target=wait_label, args=("b",))
t1.start(); t2.start()
t1.join(); t2.join()
print("threads elapsed", round(time.time() - t0, 2))On a draft Linux host (Python 3.12), output:
a
b
threads elapsed 0.2Both labels appear after roughly one sleep window, not two stacked serial sleeps [1]. That is concurrency while blocked on I/O, not proof that threads parallelize CPU.
CPU side with processes:
from multiprocessing import Process
import time
def burn(n):
x = 0
for i in range(n):
x += i * i
print("sum", x)
if __name__ == "__main__":
t0 = time.time()
jobs = [Process(target=burn, args=(500_000,)) for _ in range(2)]
for j in jobs: j.start()
for j in jobs: j.join()
print("processes elapsed", round(time.time() - t0, 2))Same host, guarded with if __name__ == "__main__": [2]:
sum 41666541666750000
sum 41666541666750000
processes elapsed 0.03Wall time drops versus one process doing both loops on a multi-core host because two interpreters run bytecode in parallel [2]. Numbers scale with core count and loop size; treat this as shape, not a benchmark gospel.
Draw the GIL in one picture
The glossary defines the GIL as a mutex that allows only one thread to execute Python bytecode at a time [3]. Threads still help when work spends time in I/O or in C extensions that release the lock during heavy native work [3] [1].
When threading wins
The threading module implements operating-system threads in the standard library [1]. Shared memory makes passing large in-memory structures cheap and makes data races likely without locks [1]. Use threads when tasks mostly wait on sockets, disks, or time.sleep, or when you fan out blocking API calls with concurrent.futures.ThreadPoolExecutor [4].
Watch shared mutable globals. The GIL does not serialize your Python logic; it serializes bytecode execution. Two threads incrementing the same counter without a lock still races.
When multiprocessing wins
multiprocessing mirrors the threading API with Process objects, but each process has its own interpreter [2]. That design exists so you can use multiple CPUs despite the GIL [3]. Costs the docs emphasize: slower startup, duplicated memory for imported modules, and queues or pipes for IPC [2].
Always protect the entry point on Windows and macOS default spawn start method [2]:
if __name__ == "__main__":
...Forgotten guards create fork bombs in notebooks and double-executed main blocks.
multiprocessing.Pool and ProcessPoolExecutor batch embarrassingly parallel maps. Profile before you pick pool size; oversubscribing RAM hurts more than idle cores.
Leave asyncio on the I/O lane
Asyncio cooperates on one thread with an event loop. It is not a GIL workaround for tight Python loops. See python async def is lazy. You can mix models carefully (async main plus executor for blocking calls) but not by spawning threads for CPU and hoping.
Measure before you swap modules
cProfile or py-spy on one representative input tells you whether time sits in time.sleep, recv, or a tight Python for-loop [3]. If the profile is wall-clock blocked on I/O, threads or asyncio deserve the first experiment [1]. If the profile is bytecode in user code, spawn a second process and compare total time including fork [2].
Multiprocessing duplicates memory for large parent heaps. Passing a ten-megabyte structure through Queue pickles it; passing a read-only blob might belong in multiprocessing.shared_memory per the docs when you outgrow toy examples [2].
The GIL can release during some C extension calls [3]. NumPy dot products may parallelize inside native code while your Python orchestration stays single-threaded for bytecode. Profile the actual library, not an imaginary pure-Python loop.
Pick a rule without dogma
| Symptom | Likely module |
|---|---|
Flamegraph stuck in socket.read | threading or asyncio [1] |
| Flamegraph stuck in pure Python loops | multiprocessing [2] |
| Heavy work in NumPy/C extension | measure first; extension may release GIL [3] |
| Need shared in-memory state | threading with locks, or redesign IPC [1] [2] |
For the OS isolation story behind processes, see threads vs processes. The vocabulary for overlapping work without claiming every core is in concurrency vs parallelism.
Logging and debugging across children
Child processes inherit the parent's file descriptors unless you configure logging to reopen files [2]. print from children can interleave on stdout; use the logging module with process names when debugging pool workers.
Jupyter notebooks that call multiprocessing without if __name__ guards are a common classroom footgun [2]. Run the same code as a script when teaching spawn rules.
ProcessPoolExecutor in one block
When you want a pool without managing Process objects directly:
from concurrent.futures import ProcessPoolExecutor
def square(n):
return n * n
if __name__ == "__main__":
with ProcessPoolExecutor(max_workers=2) as ex:
print(list(ex.map(square, range(5))))You should see [0, 1, 4, 9, 16]. Same spawn rules as raw Process [2] [4].
Where people go wrong
Spawning twenty threads to speed up a pure-Python matrix multiply. The GIL keeps one bytecode runner [3].
Using multiprocessing for tiny tasks where spawn cost dominates wall time [2].
Forking on Linux with threads already running in the parent (subtle deadlock class). Prefer spawn on cross-platform code or read the platform notes in the multiprocessing guide [2].
asyncio replaces multiprocessing for CPU work.
Sharing large objects by pickling them on every queue send without measuring copy cost [2].
Running CPU work in ThreadPoolExecutor and blaming Python for "no speedup."
Free-threaded CPython note
Upstream work on optional GIL disabling in CPython changes the table for some builds [3]. Until you deliberately install and test a free-threaded interpreter, assume the GIL story above for the default python3 on your PATH. Re-profile after any interpreter swap.
Daemon threads and shutdown
The threading docs describe daemon threads that exit when the main thread ends [1]. Background workers must finish critical sections or mark themselves non-daemon before process exit. Multiprocessing children require explicit join or pool shutdown [2]. Otherwise you lose log lines and half-written files silently.
Queue backpressure matters when producers outrun consumers [2]. An unbounded queue hides memory growth until the OOM killer arrives. Size queues to match consumer throughput and monitor RSS during load tests.
Run mp_thread_demo.py once with time and log whether threads or processes won on your box. When the profile still shows bytecode stuck under one mutex, read Python GIL: why threads are not truly parallel for the longer mutex story before you spawn another ThreadPoolExecutor. Go without async await is a useful contrast when someone asks why another language treats CPU and I/O concurrency differently by default. For streaming work without loading the whole dataset, see Python yield and iterators.
Send this to the friend who spins threads for pure Python CPU work under the GIL.

Keep this guide
Filed under Dev explainers, Dev tools
Questions about this guide
Why do my Python threads not speed up CPU math?
CPython's GIL lets only one thread execute Python bytecode at a time. Threads help with I/O waits; CPU-bound Python work usually needs multiprocessing or another process pool.
What does multiprocessing give me?
The multiprocessing docs: a Process API similar to threading, but each Process has its own interpreter and memory. That sidesteps the GIL for parallel CPU work at the cost of heavier startup and IPC.
When should I keep threading?
When tasks mostly wait on network or disk. Concurrent.futures.ThreadPoolExecutor is enough for many I/O fan-outs. Switch processes when the flamegraph shows Python bytecode as the bottleneck.
Is asyncio the same as threading?
No. Asyncio schedules coroutines on an event loop; it is a concurrency model for I/O, not a GIL bypass for CPU. See the async-def is lazy post for that lane.
What about concurrent.futures?
The concurrent.futures module wraps both ThreadPoolExecutor and ProcessPoolExecutor. Same mental model, different worker type.
Sources
- Python docs: threading, accessed 2026-12-03docs.python.org
- Python docs: multiprocessing, accessed 2026-12-03docs.python.org
- Python docs: Global Interpreter Lock, accessed 2026-12-03docs.python.org
- Python docs: concurrent.futures, accessed 2026-12-03docs.python.org
- Full Byte Developer: Python GIL threads not parallelfullbytedeveloper.com
- Full Byte Developer: Concurrency vs parallelism plainfullbytedeveloper.com
- Full Byte Developer: Python async def is lazyfullbytedeveloper.com