Sections

Python · Section 12

Concurrency and Parallelism

Concurrency vs. parallelism, CPU-bound vs. I/O-bound workloads, threading, multiprocessing, concurrent.futures, and the GIL's real, measured effect on each — a major competency at 5 years, per the roadmap.

Python overview
  1. ConceptsThe vocabulary this whole section builds on — the difference between concurrency and parallelism, the CPU-bound/I/O-bound distinction that decides which tool actually helps, and a map of the three approaches (threading, multiprocessing, async) before going deep on each.2 core2 standard4 concepts
  2. ThreadingRunning functions concurrently within one process — the threading module and Thread itself, the coordination primitives (Lock, RLock, Event, Condition, Semaphore) that keep shared state correct, and the three classic ways concurrent code goes wrong.2 core3 standard5 concepts
  3. MultiprocessingReal, separate OS processes — each with its own interpreter and memory, so the GIL does not apply across them — for genuine CPU parallelism, and the pickling cost every value pays to communicate between them.1 core1 standard2 concepts
  4. Futuresconcurrent.futures' unified interface over both thread-based and process-based concurrency — submitting work, getting a Future back, and the real, narrower rule for what can actually be cancelled.1 core1 standard2 concepts
  5. GILCPython's Global Interpreter Lock — what it is, why it exists, and its measured, opposite effects on CPU-bound versus I/O-bound threaded code, which is the practical payoff of understanding it at all.2 core2 concepts