The Global Interpreter Lock (GIL) is a mutex, or a lock, that allows only one native thread to execute Python bytecode at a time within a single CPython interpreter process. This design choice, fundamental to the most common implementation of Python (CPython), is often misunderstood as a flaw that prevents all concurrency. In reality, it is a pragmatic solution to a critical problem: the non-thread-safe nature of CPython’s memory management. The GIL’s primary purpose is to protect the integrity of the interpreter’s internal state, most notably the reference counts of all objects in memory. Without it, simultaneous operations from two threads could attempt to modify the same object’s reference count, leading to a race condition. One thread might read a reference count, be preempted, and then a second thread could deallocate the object. When the first thread resumes, it would be attempting to modify memory that has already been freed, potentially causing a crash or silent memory corruption. The GIL elegantly, if heavy-handedly, prevents this entire class of catastrophic errors by serializing access to the interpreter itself.