Learn: Concurrency¶
Four notebooks, in order. Each is self-contained, but they build on each other — the first sets up the decision framework that the next three each fill in for one of Python's three tools.
Notebooks in this section¶
- Concurrency models — concurrency versus parallelism, the I/O-bound versus CPU-bound distinction that drives every choice, and a one-paragraph tour of the GIL. Ends with a map: which of Python's three tools fits which kind of work.
- Threads and futures —
threading.Thread, then the higher-levelconcurrent.futures.ThreadPoolExecutoryou should actually reach for.submit,map,as_completed, collecting results and exceptions, and why shared mutable state needs aLock. - Processes and parallelism —
ProcessPoolExecutorandmultiprocessingfor CPU-bound work that the GIL otherwise serialises. Pickling constraints, theif __name__ == "__main__"guard, and how to measure whether parallelism actually paid off. - Async and await — coroutines, the event loop,
asyncio.run,gather, andTaskGroup. How a single thread juggles thousands of waiting connections, plus cancellation, timeouts, and the cardinal rule: never block the loop.
After these, the Recipes cover task-focused applications and the Reference has quick lookups for asyncio, concurrent.futures, and the threading/multiprocessing primitives.