Message403714
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:07 | jeff.allen | set | recipients:
+ jeff.allen, steven.daprano, docs@python, graingert |
2021-10-12 07:42:07 | jeff.allen | set | messageid: <1634024527.01.0.0254961095934.issue45435@roundup.psfhosted.org> |
2021-10-12 07:42:07 | jeff.allen | link | issue45435 messages |
2021-10-12 07:42:06 | jeff.allen | create | |
|