What, exactly, is the GIL?
April 10, 2026
read post
Most ML code is Python. This is surprising to many performance oriented engineers coming from
non-ML communities. Python is, notably slow and has the GIL, which forces it to only execute a single
thread at a time. The GIL primarily exists to make CPython’s memory management thread-safe. It has also become a load-bearing part of Python's API, as, in a classic example of Hyrum's Law, much Python code relies on the thread safety that it has created.
[1]: Funnily enough, if you google "when does Ray release the GIL?" one of the top results is from the Beyblade wiki.
Most ML code is Python. This is surprising to many performance oriented engineers coming from non-ML communities. Python is, notably slow and has the GIL, which forces it to only execute a single thread at a time. The GIL primarily exists to make CPython’s memory management thread-safe. It has also become a load-bearing part of Python's API, as, in a classic example of Hyrum's Law, much Python code relies on the thread safety that it has created.
[1]: Funnily enough, if you google "when does Ray release the GIL?" one of the top results is from the Beyblade wiki.