Skip to content
BENIBIX Learn

Global Interpreter Lock (GIL)

Development⚙️ Compilers & RuntimesConcurrency

Also known as GIL, Python GIL

A lock in Python that lets one thread run Python code at a time.

Think of it like

Think of it like a talking stick. Only the one holding it may speak.

Example

Emma runs a maths job in 4 threads on a 4-core laptop. It takes as long as 1 thread, because of the GIL. With 4 processes, each with its own GIL, it ends far sooner.

Why it matters

It is why threads rarely make Python maths faster. Python code uses processes for heavy work instead.

Definition

The global interpreter lock, or GIL, is a lock inside standard Python. It lets only one thread run Python code at a time, even on a chip with many cores. Threads still help while code waits on files or the network, because a waiting thread lets go of the lock. Python 3.13 added a build with no GIL. Python 3.14 made that build fully supported, but it is still not the default.

Example code

python
>>> import sys
>>> sys._is_gil_enabled()
True
Python 3.13 and later can tell you if the GIL is on. On the usual build, it is.

Common mistake

Thinking the GIL makes your own code safe with threads. It guards Python's insides, not your data, so you still need locks.

Key takeaways

  1. 1
    One thread at a time. For running Python code.
  2. 2
    Let go while waiting. Files and network still overlap.
  3. 3
    Optional since 3.13. A build with no GIL exists.