Re:No-GIL mode coming for Python
by kzrdude on Saturday July 29, 2023 @03:18AM
(#36917744)
Flask is pure python, isn't it?
[ Parent
| on HN ]
Re:No-GIL mode coming for Python
by qbasic_forever on Saturday July 29, 2023 @04:51AM
(#36918272)
Even pure python code could have race conditions with the GIL disabled. Stuff like accessing and modifying a dictionary item in python code is assumed and currently guaranteed to be atomic because of the GIL. Remove the GIL and decades of assumptions break.
I think that's a misconception? At least the way how I understood this issue.
Things like `map[k] = v` would be atomic both before and after nogil, and things like `map[k] += 1` are not atomic even with GIL, the read and store can be split from each other.
The GIL doesn't serialize the execution of threads, but ensures only one executes at a time. Therefore, the race condition issues you describe already exist even with the GIL. The GIL is only there to ensure that the interpreter doesn't corrupt Python objects and its internal data structures, which in the best case leads to a crash.
Re:No-GIL mode coming for Python
by imtringued on Saturday July 29, 2023 @04:12PM
(#36924064)
Come on, think about it harder. Do you really think this would even have a chance of becoming a PEP if python code was affected? If you thought even a little bit about it, then you would have come to the very simple conclusion "no" but here we are.
Re:No-GIL mode coming for Python
by paulddraper on Saturday July 29, 2023 @06:18PM
(#36925303)
In Python, race conditions with the GIL will be race conditions without the GIL, and vice versa.
....I believe so.
E.g. there's no plan to make lists, dicts, thread unsafe.