Pairs with Lesson 6: The GIL and Python's Concurrency Models.
| Term | Meaning |
|---|---|
| GIL (Global Interpreter Lock) | A single lock in CPython that a thread must hold to execute Python bytecode. Only one thread runs Python code at a time per process; it exists to keep reference-counting memory management safe without per-object locks. |
threading | Standard library module for running multiple OS threads in one process. Good for I/O-bound work (a blocked thread releases the GIL); does not give parallelism for CPU-bound work because of the GIL. |
asyncio | Standard library module for single-threaded, cooperative concurrency built around an event loop and coroutines. Code yields control at await points instead of being preempted by the OS. |
multiprocessing | Standard library module for running work in separate OS processes, each with its own Python interpreter and its own GIL. Gives true parallelism for CPU-bound work, at the cost of IPC/memory overhead to move data between processes. |
| I/O-bound vs. CPU-bound | I/O-bound work spends most of its time waiting on something external (network, disk, another service) — the CPU is idle during that wait. CPU-bound work spends its time actually computing, with no external wait to yield during. |
| Event loop | The scheduler at the core of asyncio: it runs one coroutine until it hits an await on something not yet ready, then switches to another coroutine that's ready to make progress, in a single thread. |
| Coroutine | A function defined with async def that can pause at await points and be resumed later by the event loop, without blocking the thread it's running on. |
PEP 703 added an experimental "free-threaded" CPython build (no GIL), opt-in starting with Python 3.13. It's still experimental and not the default; ecosystem support (especially C extensions) is catching up. Not yet a basis for production design decisions.