1.What the GIL is, and why it exists
The GIL is a mutex inside CPython letting only one thread execute Python bytecode at a time — even on multiple cores, two threads never run Python code simultaneously. It exists because reference counting is not thread-safe without it.
Key features
- The GIL is one mutex per CPython process — only one thread runs Python bytecode at a time
- It exists to make reference counting safe without a lock on every single object
- Threads take turns — the interpreter switches which one holds the GIL, roughly every 5ms
- A CPython implementation detail, not a language requirement — Jython/IronPython have none
- Python 3.13+ has an experimental free-threaded build (PEP 703) — not this machine's build
Where the GIL is, and is not, a CPython implementation detail
- 4 threads — in one process
- the GIL — held by exactly one thread at a time
- 1 thread runs bytecode — the other 3 wait their turn
Command
import sys
# True on a standard build; False on a free-threaded (PEP 703) 3.13+ build
print(sys._is_gil_enabled())The GIL is one mutex per CPython process, letting only one thread run bytecode at a time. A CPython detail, not a language rule.