Every few months someone discovers that their 8-thread Python program runs no faster than the single-threaded version — sometimes slower — and asks what went wrong. Nothing went wrong. The program did exactly what CPython promised. The misunderstanding is older than most codebases: threads in Python are not parallelism. They’re concurrency with a bouncer.
That bouncer is the Global Interpreter Lock. This post is about when it helps you, when it silently eats your speedup, and which of the three concurrency models to reach for — with a lab below where you can feel the difference yourself.
What the GIL actually is
The GIL is a mutex inside CPython — not the Python language, the interpreter implementation — that protects access to Python objects. Only the thread holding the GIL may execute Python bytecode. The rest wait.
It exists for a thoroughly pragmatic reason: reference counting. Every Python object carries a count of references to it, and CPython frees objects the moment the count hits zero. Without a global lock, two threads touching the same object’s refcount at once would corrupt memory, so every refcount update would need its own fine-grained locking. The GIL made the simple approach safe: one lock, held during bytecode execution, and the whole memory-management story stays correct with almost no per-object overhead.
The price is exactly what you’d expect: one thread executes Python bytecode at a time, no matter how many cores you have. Threads still exist and still work — they just take turns.
Two things worth getting straight early, because they defuse most GIL arguments:
- It’s a CPython detail, not a language rule. Other implementations made different tradeoffs. The GIL is why CPython is simple and fast for single-threaded code — and why it can’t use 64 cores from threads.
- The GIL is released during blocking operations. When a thread enters a blocking system call — a socket read,
time.sleep, disk IO — or a C extension that explicitly drops it (NumPy releases the GIL in its inner loops), other threads can run. This single fact is the entire difference between the two workloads below.
The only distinction that matters: CPU-bound vs IO-bound
Forget threads, processes, and asyncio for a moment. There are two kinds of work, and the GIL treats them completely differently.
CPU-bound work is pure computation in Python bytecode: hashing, parsing, transforming data structures, running your own algorithms. The thread holds the GIL for the entire duration, because it’s executing bytecode the entire duration. Adding threads to CPU-bound work is adding more people to a queue for a single cashier — the line gets longer, the throughput doesn’t move.
IO-bound work is mostly waiting: HTTP requests, database queries, file reads, sleeps. During the wait, the thread isn’t executing bytecode at all — it’s parked inside a blocking syscall, and it releases the GIL while parked. The other threads run. So with IO-bound work, threads genuinely overlap: while one waits on the network, seven others make progress.
If you take one rule from this post, it’s this: name your workload before you pick your tool. Everything else follows.
Threads: brilliant for IO, a trap for CPU
Threads are the cheapest concurrency Python offers: one interpreter, shared memory, no serialization of arguments. For IO-bound work they’re exactly right:
from concurrent.futures import ThreadPoolExecutor
import urllib.request
def fetch(url: str) -> bytes:
# the GIL is released during the blocking socket read
with urllib.request.urlopen(url) as resp:
return resp.read()
with ThreadPoolExecutor(max_workers=8) as pool:
pages = list(pool.map(fetch, urls))
Eight threads, eight simultaneous in-flight requests, one shared process. The GIL is barely involved — each thread holds it only for the microseconds of Python between syscalls.
But point the same construct at CPU-bound work and you get the queue:
from concurrent.futures import ThreadPoolExecutor
import hashlib
def sha256_of(chunk: bytes) -> str:
return hashlib.sha256(chunk).hexdigest() # holds the GIL throughout
with ThreadPoolExecutor(max_workers=8) as pool:
digests = list(pool.map(sha256_of, chunks)) # no faster than serial
The threads take turns. You pay thread-startup cost and lock contention for the privilege of running sequentially with extra steps. This is the single most common Python performance bug I’ve seen in production code, and it always looks the same: someone “parallelized” a loop with threads and the wall-clock time didn’t move.
One more honest caveat about threads: shared memory means shared mutable state, and the GIL does not make your data structures thread-safe in any useful sense. It makes individual bytecodes atomic-ish, which is a much weaker guarantee than “my counter increments correctly.” Use locks for shared state; don’t rely on the GIL for correctness.
Processes: the GIL sidestep, with a tax
If threads can’t use multiple cores for CPU work, what can? Separate interpreters. Each process runs its own CPython, with its own GIL — and two processes on two cores genuinely execute bytecode simultaneously.
from concurrent.futures import ProcessPoolExecutor
import hashlib
def sha256_of(chunk: bytes) -> str: # must be top-level: it gets pickled
return hashlib.sha256(chunk).hexdigest()
if __name__ == "__main__": # required with the spawn start method
with ProcessPoolExecutor(max_workers=8) as pool:
digests = list(pool.map(sha256_of, chunks))
This is the standard answer for CPU-bound Python, and it works. But processes are not free threads with a different name. The tax has three parts:
- Startup. Spawning a worker boots a whole interpreter — slow enough that a single worker can be slower than serial. Processes only pay off when the parallel work outweighs the fixed cost.
- Memory. Each worker is a full copy of the interpreter and your imported modules. Memory scales roughly ×N.
- IPC. Arguments and results cross the process boundary pickled. That means your worker function must be picklable (top-level, no lambdas or closures), your data must survive a serialize/deserialize round-trip, and large payloads pay a real copy cost.
The if __name__ == "__main__" guard matters: with the spawn start method (the default on macOS and Windows), each worker re-imports your module, and without the guard it would recursively spawn workers forever. On Linux the default is still fork, which is faster but famously unsafe combined with threads — another quiet footgun in the same neighborhood.
Use processes when the work is CPU-bound and chunky enough that the tax is noise. Don’t use them for IO-bound work: paying a full interpreter per worker to spend 99% of its life waiting on a socket is the wrong trade.
Asyncio: one thread, thousands of waits
Asyncio looks like a third option but it’s really a different axis. There is no parallelism at all — one thread, one event loop. Coroutines run until they hit await, then yield control back to the loop, which resumes whichever task is ready.
import asyncio
import aiohttp
async def fetch(session, url):
async with session.get(url) as resp: # yields here while waiting
return await resp.text()
async def main(urls):
async with aiohttp.ClientSession() as session:
return await asyncio.gather(*(fetch(session, u) for u in urls))
asyncio.run(main(urls))
While 999 connections wait on the network, the loop runs the one that’s ready. No GIL contention (there’s only one thread), no process overhead, tiny memory footprint. This is why asyncio dominates IO-bound servers: it handles connection counts that would drown a thread pool.
But the single-threadedness is also the limit. CPU-bound work in asyncio still runs one task at a time — the loop can’t parallelize what never yields. (And asyncio.to_thread just moves the work to GIL-limited threads; it doesn’t escape the trap.) The mental model: asyncio gives you concurrency without parallelism — brilliant at juggling waits, useless at splitting compute.
Free-threaded Python: the 2026 status, honestly
This is the part that changed recently enough to be worth checking against the docs rather than memory. PEP 703 — “Making the Global Interpreter Lock Optional in CPython” — proposed a --disable-gil build configuration, and it was accepted in 2023 with an explicitly gradual rollout in three phases.
Here’s where each phase stands, verified against the official sources:
- Phase I — experimental (Python 3.13). The free-threaded build shipped as opt-in: build with
--disable-gil, or install thet-suffixed binary (python3.13t). Explicitly experimental. - Phase II — supported, still optional (Python 3.14). PEP 779 set the acceptance criteria for “officially supported but still optional” status, targeting 3.14. The design is considered final and the APIs stable — but you still have to choose it. It is not the default interpreter.
- Phase III — the default. Not decided. The PEP explicitly leaves the default flip to a future decision, hinging on ecosystem support and demonstrated real-world benefit.
The free-threading HOWTO in the official docs is the ground truth for the details, and it’s worth knowing what it actually says:
- A free-threaded build can still run with the GIL at runtime:
PYTHON_GIL=0/python -X gil=0(and1to re-enable). The GIL isn’t gone from the binary; it’s disabled. sys._is_gil_enabled()tells you the runtime truth;sysconfig.get_config_var("Py_GIL_DISABLED")tells you about the build.- The ecosystem caveat is the big one. Importing a C extension that hasn’t declared free-threading support automatically re-enables the GIL for the whole process — with a warning. Your no-GIL program silently becomes a GIL program because of one unaudited dependency. There are public trackers for which popular packages are ready; check before you deploy.
- Thread safety at the Python level is similar to the GIL build — built-in
dict,list, andsetuse internal locks — but “similar” is doing work there. Code that was accidentally thread-safe because the GIL serialized everything can now race for real. The docs recommend explicit locks over relying on container internals. - There are costs even when it works: roughly 1–8% single-threaded overhead on the pyperformance suite (about 1% on macOS ARM, up to 8% on x86-64 Linux) and higher memory use, from the mimalloc allocator, deferred memory reclamation (QSBR), and per-object locking machinery.
So the honest 2026 summary: free-threaded Python is real, supported, and no longer experimental — and it is still opt-in, still ecosystem-limited, and still not something to assume in library code. If you’re writing an application (not a library) with CPU-bound threaded work and you can audit your dependency tree, it’s worth an experiment. For everyone else, the threads/processes/asyncio decision above is still the whole game.
The decision guide
| Workload | Reach for | Why |
|---|---|---|
| IO-bound, moderate scale | Threads (ThreadPoolExecutor) | GIL released during waits; cheapest option |
| IO-bound, massive scale | Asyncio | One thread juggles thousands of waits; no thread-per-connection cost |
| CPU-bound, pure Python | Processes (ProcessPoolExecutor) | Each process has its own GIL; true multi-core |
| CPU-bound, in C extensions | Threads can work | NumPy et al. release the GIL in inner loops — verify per library |
| CPU-bound, audited deps, app code | Free-threaded build (3.13t/3.14t) | Threads with real parallelism; still opt-in, still needs the audit |
Try it live — the lab below simulates all of it:
- Every thread needs the GIL to execute Python bytecode. With pure-CPU work the threads take turns holding it — 8 threads finish no faster than 1.
- You still pay thread overhead (startup, context switches, lock contention), so it can land slightly slower than serial.
- Threads only help when the work releases the GIL: blocking IO, or C extensions like NumPy that drop it in their inner loops.
Two things to notice while you play. First, flip to the CPU-bound workload and watch the threads bar: eight workers, no speedup — then toggle the free-threaded build and watch threads jump to match processes. That’s PEP 703 in one checkbox. Second, on the IO-bound workload, asyncio beats everything: the waits overlap almost perfectly on a single thread, with none of the process tax.
The GIL was never a bug to be fixed so much as a tradeoff to be understood: CPython chose simple, fast single-threaded execution, and charged multi-core threading as the price. Threads for waiting, processes for computing, asyncio for juggling — name the workload, and the tool picks itself.