-
-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document atomic operations on builtin types #69530
Comments
Please document what builtin type operations are actually atomic. (There are some blogs / tutorials online, but information is outdated and not authoritative) |
We actually don't have any guarantees written down because we have never formalized them. It was discussed at the PyCon language summit this past year -- https://lwn.net/Articles/640177/ -- but it didn't lead to anyone writing a proposal to formalize the memory model. |
I wonder...personally I prefer to program in asyncio style rather than threading style, where one doesn't have to worry about atomicity. Maybe Python shouldn't make any atomicity guarantees. |
The language doesn't make any guarantees about set operation atomicity. Different implementations such as PyPy, Jython, and IronPython are free to make different choices than CPython. In general, users should make no assumptions about atomicity unless explicitly documented and tested. The wise course of action is to use mutexes when there is any doubt. FWIW, it is difficult to make blanket statements about the methods on sets because the atomicity depends on the objects looked up or stored in the sets rather than the set itself. Aside from trivial calls to __sizeof__ and __len__, most set methods potentially call __hash__ or __eq__ on the set elements either of which could make a callback into pure python code. Likewise, any reference count decrement can potentially make a callback as well. |
This question has been asked multiple times before. I think it should be documented that as far as the language goes, there is no answer. Raymond's answer is a start. Dima, where would you expect to find such a disclaimer (other than in the FAQ)? |
Ideally I'd like 2 sources:
|
I think what Terry was asking was, where would you expect to see the disclaimer that *no* operations are guaranteed to be atomic? That's what we're inclining toward (though we'll probably need a signoff from Guido). |
To clarify, Python language disclaimer can be in the general atomic operations or multithreading section. What I'd really like to see is documented, practical CPython and stdlib behaviour. I'm under the impression that there's quite a bit of code out there that relies on what's actually atomic in CPython. d. |
I think you are correct, and I wouldn't be surprised if there is some in the stdlib as well. |
Yes, I was asking where to put the disclaimer. The thread docs would be approriate if there is nothing already. Guido has been very reluctant to put any performance guarantees in the language reference. I believe he said that O(f(n)) info even for CPython should be in the wiki -- and taken as a guideline, not a iron guarantee. Further discussion might be better directed to python-ideas, after a search of the pydev and python-ideas archives (most easily done with the gmane mirrors, I believe). |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: