Threads, Processes and the GIL

What the interpreter lock actually locks, why an increment can lose a count, and when a process is the only thing that helps - with the mechanism runnable on every page.

7 modules Free, no login Updated 15 September 2026

About this track

Python's threads are real operating-system threads that are not allowed to run Python at the same time. One lock - the GIL - is held by whichever thread is executing bytecode, which is why threads help a program that waits and do nothing for a program that computes.

This track builds that from the bytecode up: the three operations an increment compiles to, the switch that lands between them, the lock protocol that prevents it, and the pickle boundary that decides what a process can be sent. A note on every page: the browser interpreter has no OS threads, so the editors run the mechanism and the thread-spawning examples are shown with their output.

All 7 modules, in teaching order

  1. 01The GIL, and What It Actually Locks
  2. 02Race Conditions: Why x += 1 Is Three Operations
  3. 03Locks, and the Four Ways They Go Wrong
  4. 04Threads or Processes: What Is and Is Not Shared
  5. 05concurrent.futures: One Interface for Both
  6. 06Handing Work Between Threads with a Queue
  7. 07Choosing Between Threads, Processes and Async

Other tracks