4. Languages and runtimesPython internals
Python internals
Python internals are what the standard interpreter, CPython, actually does when it runs your code. Every value is a heap object carrying a reference count, the number of names and containers pointing at it; when that hits zero, the object is freed immediately, and a separate cycle collector catches groups of objects that only point at each other. On top sits the global interpreter lock, or GIL, which lets only one thread run Python bytecode at a time, so threads help with waiting on I/O but not with heavy computation. This explains everyday surprises, like a mutable default argument being shared across calls, or x += 1 still racing between threads.
In this lesson: A GIL sim with threads passing a token. Refcount badges on objects, and a cycle only the cyclic GC catches. Generators as paused frames.