Earlier quoted context omitted.
Relying on implementation behavior, even if it’s very visible and hasn’t changed for a few decades, is morally wrong and reprehensible. Only the letter of the standard has any bearing on correct reality.
> morally wrong That's a wild one
The Changing "Guarantees" Given by Python's Global Interpreter Lock
91–100 of 142 posts
Re: The Changing "Guarantees" Given by Python's Global Interpreter Lock
#92Code that assumes that something is going to be atomic because of the GIL (or any other implementation detail) is simply broken. If you need something to be atomic you should be explicit about that and use mutex or something.
If major libraries and user code are constantly incorrect, but work because of an implementation detail, then removing that implementation detail becomes extraordinarily difficult, verging on impossible.
It would be like retrofitting your language to distinguish valid unicode text from arbitrary byte strings, when you'd previously treated them as equivalent.
Re: The Changing "Guarantees" Given by Python's Global Interpreter Lock
#93>> I have at least one very concrete example of code that someone assumed to be atomic: request_id = self._next_id self._next_id += 1 To think that is thread safe is just naive. Once you understand the potential problem you can look at the code and ask "why shouldn't this be unsafe?" Since there is nothing explicitly preventing the problem. After reading TFA (lazily I admit) I still don't know why that code is thread…
Re: The Changing "Guarantees" Given by Python's Global Interpreter Lock
#94Earlier quoted context omitted.
Conversely, I've worked on backend, data processing-type applications for most of my career, much of it in Java but some (especially recently) in Python, and the GIL is a huge limiting factor for writing efficient, readable Python code. I've had to write very annoying Python code using the multiprocessing library to get around the GIL, and ultimately it works, but it's ugly and clunky and overall just a pain. And rem…
I think multiprocessing is quite sensible in Python (comparing to async for an example)
Re: The Changing "Guarantees" Given by Python's Global Interpreter Lock
#95>> I have at least one very concrete example of code that someone assumed to be atomic: request_id = self._next_id self._next_id += 1 To think that is thread safe is just naive. Once you understand the potential problem you can look at the code and ask "why shouldn't this be unsafe?" Since there is nothing explicitly preventing the problem. After reading TFA (lazily I admit) I still don't know why that code is thread…
On the other hand, it is safe from a memory-access perspective; the read from `self._next_id` will never dereference a partially-mutated invalid pointer or read a partially-mutated value.
Re: The Changing "Guarantees" Given by Python's Global Interpreter Lock
#96>> I have at least one very concrete example of code that someone assumed to be atomic: request_id = self._next_id self._next_id += 1 To think that is thread safe is just naive. Once you understand the potential problem you can look at the code and ask "why shouldn't this be unsafe?" Since there is nothing explicitly preventing the problem. After reading TFA (lazily I admit) I still don't know why that code is thread…
Re: The Changing "Guarantees" Given by Python's Global Interpreter Lock
#97Earlier quoted context omitted.
Relying on implementation behavior, even if it’s very visible and hasn’t changed for a few decades, is morally wrong and reprehensible. Only the letter of the standard has any bearing on correct reality.
Python's semantics do not have a standards document or specification. It's based on its reference implementation (CPython) and different variations of Python even have different semantics (Jython, IronPython, PyPy). The library is documented, and the syntax is also documented, but the semantics themselves are not.
The language reference at https://docs.python.org/3/reference/index.html "describes the syntax and “core semantics” of the language.".
There has been a distinction between Python-the-language and CPython-the-implementation ever since JPython back in the 1990s. For example, reference counting is a CPython implementation details. The reference manual says only:
> Objects are never explicitly destroyed; however, when they become unreachable they may be garbage-collected. An implementation is allowed to postpone garbage collection or omit it altogether — it is a matter of implementation quality how garbage collection is implemented, as long as no objects are collected that are still reachable.
(Quoting https://docs.python.org/3/reference/datamodel.html )
Re: The Changing "Guarantees" Given by Python's Global Interpreter Lock
#98Earlier quoted context omitted.
I dunno about that. There's a lot of Python out there with worker threads dumping their output into a shared "results" dict on the assumption that those insert operations are atomic.
Python says those insert operations are atomic. https://docs.python.org/3/faq/library.html#what-kinds-of-glo... For example, the following operations are all atomic (L, L1, L2 are lists, D, D1, D2 are dicts, x, y are objects, i, j are ints): L.append(x) L1.extend(L2) x = L[i] x = L.pop() L1[i:j] = L2 L.sort() x = y x.field = y D[x] = y D1.update(D2) D.keys()
Re: The Changing "Guarantees" Given by Python's Global Interpreter Lock
#99Earlier quoted context omitted.
Python doesn't have a standards document. It has a reference implementation that defines the language. IOW, the python implementation is the standard, and therefore any code that relies on an implementation detail in the reference implementation is, by definition, correct.
> Python doesn't have a standards document. It has a reference implementation that defines the language. That's not quite strictly true, Python does have a documented "Language Reference": https://docs.python.org/3/reference/index.html If there is a contradiction between the Language Reference and CPython then one, or both, of them needs to be updated and it's treated on a case by case basis. If an alternative Python…
Re: The Changing "Guarantees" Given by Python's Global Interpreter Lock
#100Earlier quoted context omitted.
The GIL in an implementation detail of CPython, it's not part of Python the language.
There is no language standard. The GIL is a Python language feature because it's a CPython feature.
What would it mean to have a language standard? A publication from ISO or ECMA?
I ask because the Python Language Reference at https://docs.python.org/3/reference/index.html seems to be a (terse) language standard. Among other things, it highlights some of the things which are implementation defined, rather than language defined.