Author serhiy.storchaka
Recipients docs@python, graingert, jeff.allen, pablogsal, pitrou, serhiy.storchaka, steven.daprano
Date 2021-10-12.12:36:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1634042186.45.0.727577679094.issue45435@roundup.psfhosted.org>
In-reply-to
Content
sort() is atomic, even if GIL is released during executing custom __lt__. It is guaranteed that no operations on the list in other threads can affect the result of sort().

I do not understand what non-atomic you see in x = L[i]. The value of x is determined by values of L and i at the start of the operation. GIL is not released during indexing L, and if it is released between indexing and assignment, it does not affect the result.

The FAQ answer is specially about built-in types, it is not related to types with overwritten __getitem__ etc.

The most questionable examples are dict operations. But even they provide some kind of atomacity. But you perhaps need to know internals to understand limitations.

We perhaps should explicitly document what non-trivial operations are atomical (for example list and dict copying is atomic) and whether atomacity is the part of the language specification or CPython implementation detail. In many places in the stdlib the code relies on GIL for atomacity.
History
Date User Action Args
2021-10-12 12:36:26serhiy.storchakasetrecipients: + serhiy.storchaka, pitrou, steven.daprano, docs@python, jeff.allen, graingert, pablogsal
2021-10-12 12:36:26serhiy.storchakasetmessageid: <1634042186.45.0.727577679094.issue45435@roundup.psfhosted.org>
2021-10-12 12:36:26serhiy.storchakalinkissue45435 messages
2021-10-12 12:36:26serhiy.storchakacreate