The GIL, race conditions, locks, pools, and 12 production patterns โ with interactive diagrams
What a thread is, why the GIL makes Python threading weird, and how shared memory, race conditions, and the event model work โ read this first.
Create, start, and join threads. The four verbs you'll use every time.
Why counter += 1 corrupts, and how a Lock fixes it.
Producer/consumer done right with queue.Queue and backpressure.
The modern way. submit, map, and Futures.
Event, Condition, Semaphore, and Barrier โ coordinating threads.
How two locks freeze forever, and the ordering rule that prevents it.
Give each thread its own copy with threading.local.
Daemon threads, states, and what happens when main exits.
You can't kill a thread. Stop flags, sentinels, and clean exits.
Delayed and repeating work with threading.Timer.
Cap concurrency with a Semaphore; smooth throughput with a token bucket.
as_completed, wait, timeouts, and exception handling.
Why it exists, when it's released, and free-threaded Python 3.13+.
The decision guide: when each model wins, and why.
What's atomic in CPython, visibility, and why not to rely on it.