Skip to content
IT glossary
BackendUpdated December 3, 2026

GIL

In CPython with the Global Interpreter Lock enabled, only one thread per interpreter can run Python bytecode at a time. A thread waiting for network data can release the lock so another thread can run.

Also known as: Global Interpreter Lock

What the GIL controls

The Global Interpreter Lock (GIL) is a lock used by CPython, the most common implementation of Python. With the GIL enabled, a thread must hold it to execute Python bytecode. Two threads in the same interpreter can take turns running Python code, but they can't both execute bytecode at the same instant on separate cores. That's a property of the runtime, not a rule of the Python language.

When threads still help

The lock makes it easier for CPython to protect internal state such as object reference counts. The interpreter periodically gives other threads a chance to acquire the lock. It also releases the lock around many blocking I/O operations: while one thread waits for data from a socket, another can run Python code. Native extensions can explicitly release the GIL during computation, too. So a Python program can use multiple cores without having multiple threads execute Python bytecode at once.

Example: choosing an executor

Say a backend needs to call three independent HTTP APIs using a blocking client. A ThreadPoolExecutor can overlap those calls: while one worker waits for a response, another sends its request. Now imagine the same pool running three large loops written in pure Python. With the GIL enabled, the workers take turns executing those loops rather than spreading the bytecode across three cores. A ProcessPoolExecutor can run those jobs in parallel because each worker process has its own interpreter and GIL. Measure before switching: process startup and moving data between workers can outweigh the gains for small jobs.

Common misconceptions

  • The GIL doesn't make shared application state thread-safe. If two threads both check that an item is in stock and then decrement the count in a separate step, both can see the last item before either decrements it. For shared in-memory state, use a lock around the whole check-and-update operation.
  • asyncio isn't a way around the GIL. It lets tasks take turns while waiting for I/O. A long computation run directly on the event-loop thread still prevents other tasks on that loop from making progress.
  • Not every CPython build runs with the GIL enabled. CPython has offered a separate free-threaded build since Python 3.13. It can run Python threads in parallel with the GIL disabled, though importing an extension that doesn't declare free-threading support can re-enable it.

What interviewers look for

If asked whether Python threads make a backend faster, identify the bottleneck first. For I/O-bound work, threads can overlap waits. For CPU-bound work in pure Python, threads in the same interpreter generally won't deliver multicore speedups with the GIL enabled. Explain why processes change that result, and distinguish pure Python work from native code that releases the lock.