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.

Further reading