Python:GIL
lastmod 2025-09-18created 2017-01-245 edits
CPython and PyPy guarantee synchronization between threads by using the Global interpreter lock (a.k.a. GIL) to prevent two or more threads from running at the same time.
However, this is only how CPython and PyPy implement threads; the Python spec says nothing about not running two or more threads at the same time or about using a GIL. CPython and PyPy simply implemented the GIL because they judged that using it brings many benefits, even at the cost of efficiency.
Python GIL
In Python, all data structures are thread-safe and most operations are atomic. This is due to the CPython GIL; thanks to it, Python is freed from cumbersome concurrency management, but on the other hand it ends up with the odd structure where only one thread runs.
Python_and_the_GIL.png