Why does Python have a GIL? What does it mean for my threaded code?
Python interviews at any company doing parallelism probe this — answers like "Python is just slow" fail.
GIL = one lock that only one thread can hold while executing Python bytecode. Protects CPython's reference-counted memory management from race conditions.
Impact: CPU-bound Python threads don't parallelize — they take turns. I/O-bound code DOES benefit from threads because the GIL is released during I/O.
Workarounds: multiprocessing (separate interpreter per process, separate GIL each), asyncio for I/O concurrency, C extensions that release the GIL for numeric work (numpy, PyTorch).
PEP 703 (Python 3.13+) introduced optional no-GIL builds ("free-threaded"). Still maturing as of 2026; most production is on GIL builds.
Not all Pythons have a GIL: Jython and IronPython never did. PyPy has one.
GIL exists because CPython uses reference counting, and making ref counts atomic on every single operation would be catastrophic for single-threaded performance. Instead, one global lock serializes bytecode execution. The interview-level implication: CPU-bound threads don't speed up (they serialize), but I/O-bound threads do (GIL is released during blocking I/O). So for scraping, socket handling, DB queries — threads work. For number crunching — use multiprocessing, or use a library (numpy, torch) that drops the GIL during its C work. Python 3.13's free-threaded build is real progress but most production code still runs with GIL. My rule of thumb: CPU-bound → multiprocessing or C extension; I/O-bound → asyncio (cleaner than threads); mixed → thread pool with a queue.
asyncio does NOT bypass the GIL — it just avoids blocking by cooperating. Still one Python thread.
numpy operations often release the GIL during compute — that's why numpy + threading can scale on CPU work.
HireMe AI (即答侠) maps the GIL topic to real-world choices (Gunicorn workers vs threads) so answers feel lived-in.
3.13+ has experimental --disable-gil builds. Some C extensions aren't thread-safe without GIL; check your stack before adopting.
Tried it (Greg Stein's 1999 patch). Single-threaded performance dropped ~2x. Until recently no one found a way to remove GIL without paying that cost.
HireMe AI listens to your interview in real-time, detects questions, and generates instant answer suggestions — so you never freeze up again.
Try HireMe AI Free