Python’s Global Interpreter Lock
In Python’s reference implementation (CPython) the Global Interpreter Lock (GIL) is a mutex which limits execution of Python bytecode to run on only a single thread at a time. This prevents race conditions where multiple threads might otherwise cause simultaneous modification to Python’s internal memory states.
The GIL only applies to Python code, so C code is able to release the GIL. Many IO operations, as well C extensions such as NumPy, do release the GIL whenever possible, but its presence still prevents Python from taking full advantage of multiple CPU cores.
- Corbet, Jonathan. “A Viable Solution for Python Concurrency.” LWN.net, October 14, 2021. https://lwn.net/SubscriberLink/872869/0e62bba2db51ec7a/.