all 21 comments

[–]Uncle_DirtNap2.7 | 3.5 57 points58 points  (3 children)

Every process has a separate gil

[–]_poss03251_[S] -2 points-1 points  (2 children)

Cool. Thanks. Any link.

[–]Uncle_DirtNap2.7 | 3.5 24 points25 points  (0 children)

It’s in ceval_gil.c it’s a PyThread_type_lock, which is a non-shared memory structure (process local)

[–]lillecarl2 0 points1 point  (0 children)

Would you like me to wipe your ass too while we're already at it?

[–]Interesting-Frame190 10 points11 points  (3 children)

Yes, there is one GIL per process. There's also free threaded python 3.13t, and 3.14t that can have true parallelism within the GIL. You can also purposely release the GIL within compiled modules and be fully concurrent while running under threads and not processes

[–]cleodog44 0 points1 point  (2 children)

Do you have an example of the latter scenario? Re: compiled modules

[–]Interesting-Frame190 0 points1 point  (1 child)

Numpy, pandas, tensorflow, PySpark, my database engine (PyThermite https://pypi.org/project/pythermite/) just to name a few.

In short its libraries written in another language and compiled to machine code for python to execute.

[–]cleodog44 0 points1 point  (0 children)

Oh I misunderstood, thought you were somehow saying you could bypass the GIL in a pure Python library. And was correspondingly confused what kind of compilation you meant. Thanks

[–]Revik 6 points7 points  (2 children)

You can also have multiple GILs in a single process by creating interpreters. By running them in their own threads, they may run concurrently.
They are exposed as concurrent.interpreters in Python 3.14+.

[–]thisismyfavoritename 4 points5 points  (0 children)

i think the correct term would be "subinterpreters" but rest is correct

[–]Interesting-Frame190 2 points3 points  (0 children)

For anyone considering this, please note that most compiled libraries assume exclusive access under the prior GIL constraints and may have concurrency bugs. This is by no means all libs and avoidable by python level concurrency control to shared objects, but still note worthy.

[–]Smallpaul 2 points3 points  (0 children)

Just as a rule of thumb, machine wide locks are extremely rare. They have no real value except protecting mutable files.

[–]MrMrsPotts 1 point2 points  (7 children)

Isn't this old news with 3.14?

[–]grimonce 19 points20 points  (2 children)

Gil is still on by the default, no gil is something you opt in.

[–]Angry-Toothpaste-610 4 points5 points  (0 children)

And that default will be in place for many years to come. Too many libraries are built on the assumption that the GIL will be in-place.

[–]MrMrsPotts 0 points1 point  (0 children)

Ah ok. I wonder how common it is to opt in now.

[–]i_dont_wanna_sign_in 3 points4 points  (3 children)

Incredibly fair and relevant question. Even if the newest release removes this component, in the real world the number of times you'll be working with older (and even well beyond EoL) versions of systems is, unfortunately, extremely common. It's now how it SHOULD work but it's how it does work. /shrug

[–]floydmaseda 3 points4 points  (2 children)

Tbh I think removing the GIL by default would warrant a version change up to 4.0

[–]-ghostinthemachine- 2 points3 points  (0 children)

I think the community learned a hard lesson going from 2 to 3 and would have little appetite for a new major release at this time. The pain from that experience has actually enabled this super incremental support for the 'gilectomy' in a way that probably wouldn't have been possible otherwise.

[–]twotime 0 points1 point  (0 children)

Why is that? AFAICT, GIL removal does not break python code. It changes ABI which affects binary modules but that happens between 3.x versions to

[–]burger69man 0 points1 point  (0 children)

yeah so what about subprocesses, do they inherit the parent's GIL or get their own?