Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45435>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to