I believe that GIL-removal projects aim to preserve this behaviour:
https://peps.python.org/pep-0703/#container-thread-safety
That's why gilectomy carries an unreasonable single-threaded performance cost: many operations now need to take a lock where before they relied on the GIL.
Re:Our Plan for Python 3.13
by umanwizard on Thursday June 15, 2023 @05:46PM
(#36347006)
Why do you consider code that relies on the GIL to be buggy? Isn't the GIL a documented, stable part of Python? (Hence why it will probably never be removed).
5th sentence in my comment:
> I’ve even seen code in production that has these bugs, because they’re sometimes dumb performance enhancements, rather than bugs, unless you happen to use a Python interpreter without a GIL, especially one that that doesn’t exist yet.
Re:Our Plan for Python 3.13
by miraculixx on Thursday June 15, 2023 @06:46PM
(#36347808)
The GIL protects interpreter resources, not your program. If you have concurrent access to your own objects you need your own locks.
“Interpreter resources” are just python primitives, from the user perspective. And, from that perspective, you can sometimes get away without using user managed locks, by relying on the GIL, in your objects. For example, you can trivially use a list as a multi threaded queue, using `.append()` and `.pop()`.
As an early python programmer, I copy pasted these types of answers. My old threaded code absolutely has these bugs. I’ve even seen code in production that has these bugs, because they’re sometimes dumb performance enhancements, rather than bugs, unless you happen to use a Python interpreter without a GIL, especially one that that doesn’t exist yet.
Great care would have to be taken to make sure the GIL was not disabled by default, for anything an existing thread touches (or some super, dynamic aware, smarts to know if it can be disabled).