What Is the Global Interpreter Lock (GIL) in Python?

The GIL lets only one thread execute Python bytecode at a time in CPython, limiting true multi-threaded CPU parallelism. Learn why it exists and how to work around it.

Published September 18, 2026

The Global Interpreter Lock (GIL) is a mutex in CPython that lets only one thread execute Python bytecode at a time. It protects memory management but means threads do not speed up CPU-bound Python code.

The concept

CPython's memory management uses reference counting, which is not thread-safe. The GIL is a simple way to keep it safe: a thread must hold the lock to run bytecode.

Threads still help for I/O-bound work (network, disk) because the lock is released while waiting. For CPU-bound work use multiprocessing, which runs separate interpreters with separate GILs.

Two threads sharing one lock

runsblockedThread Ahas the GILGILone at a timeThread Bwaits
Only the thread holding the GIL runs Python code.

Practical examples

CPU-bound: use processes

from multiprocessing import Pool

def square(n): return n * n

with Pool() as p:
    print(p.map(square, range(10)))

I/O-bound: threads are fine

from concurrent.futures import ThreadPoolExecutor
import urllib.request

with ThreadPoolExecutor(8) as ex:
    pages = list(ex.map(lambda u: urllib.request.urlopen(u).read(), urls))

asyncio for many connections

import asyncio
async def main():
    await asyncio.gather(fetch(1), fetch(2))
asyncio.run(main())

Common mistakes

  • Adding threads to a CPU-heavy loop and expecting speed-ups.
  • Assuming the GIL makes your code thread-safe — compound operations still need locks.
  • Blaming the GIL for I/O-bound slowness that comes from the network.

Key takeaways

  • One thread runs Python bytecode at a time.
  • Threads help I/O; processes help CPU.
  • Python 3.13 adds an experimental free-threaded build.

FAQ

Do other Python implementations have a GIL?

Jython and IronPython do not; PyPy has one.

Will the GIL be removed?

PEP 703 made it optional in an experimental build starting with Python 3.13.

More Python articles