Author jeff.allen
Recipients docs@python, graingert, jeff.allen, steven.daprano
Date 2021-10-12.07:42:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I'm interested in Thomas' reasons, but here are some of mine (as far as I understand things):

1. It is specific to one interpreter implemented in C, equipped with a GIL, and on certain assumptions about the byte code interpreter and the implementation of built-ins, that may not hold long-term. 

2. In x = L[i], the index and assignment are distinct actions (in today's byte code), allowing L or i to change before x is assigned. This applies to multiple other of the examples.

3. A compiler (even a CPU) is free to re-order operations and cache values in unguessable ways, on the assumption of a single thread.

4. Code written on these principals is fragile. It only takes the replacement of a built-in with sub-class redefining __getitem__ (to support some worthy aim elsewhere in the code) to invalidate it.

5. sort() is not atomic if an element is of a type that overrides comparison in Python. (Nor is modifying a dictionary if __hash__ or __eq__ are redefined.)

If you want retain the question, with a better answer, the last sentence is good: "When in doubt, use a mutex!", accompanied by "Always be in doubt."
Date User Action Args
2021-10-12 07:42:07jeff.allensetrecipients: + jeff.allen, steven.daprano, docs@python, graingert
2021-10-12 07:42:07jeff.allensetmessageid: <>
2021-10-12 07:42:07jeff.allenlinkissue45435 messages
2021-10-12 07:42:06jeff.allencreate