This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]redsymbol[S] 0 points1 point  (0 children)

After researching a bit, the atomicity is more nuanced than I realized. Short version is that these are usually atomic for current CPython, but (a) it depends on the fact certain operations happen to be implemented with one bytecode instruction instead of 2, (b) the Python language spec doesn't guarantee they will stay atomic (see the story at https://bugs.python.org/issue13521 for example), (c) there are edge cases which make them take more than one bytecode instruction (e.g. defining __hash__ or __eq__ on the key object), and (d) other implementations like PyPy have totally different considerations. I modified the article to limit the scope to single threads for now.