I'm diving into Python's internals and I'm a bit confused about the Global Interpreter Lock (GIL). Can anyone clarify if each Python process has its own GIL, or is there just one GIL for the entire machine? I understand that memory is managed uniquely per process, so should it be one GIL per process? The documentation on multiprocessing suggests that it allows for true parallelism, which adds to my confusion. Any insights would be appreciated!
3 Answers
That's correct, there is one GIL per process. Starting from versions 3.13t and 3.14t, Python offers some options for true parallelism even within threads. You can choose to release the GIL when using compiled modules, allowing for full concurrency while still in a threaded environment.
Every Python process indeed has its own separate GIL. So, to your question, yes, it's one GIL per process. This setup allows each process to manage its own memory independently, which is pretty crucial for parallel processing.
But isn't this something we already knew with version 3.14?
That's right, but keep in mind that the GIL is still enabled by default. Opting out of it is an intentional choice you have to make.
Good point! Even if newer versions change things, many developers still deal with older versions regularly, so it's a relevant concern.

Awesome, thanks for the clarification! Got any further reading on this?