-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-134009: Expose PyMutex_IsLocked
in the public C API
#134365
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
base: main
Are you sure you want to change the base?
Conversation
The `PyMutex_IsLocked()` function is useful in assertions for verifying that code maintains certain locking invariants.
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
|
||
Returns non-zero if the mutex *m* is currently locked, zero otherwise. | ||
|
||
.. note:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should consider promoting this note to a warning. I feel like a note doesn't address the actual severity of using this for control flow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the note is appropriate. The API does exactly what it name suggests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but it's a pitfall that I commonly see people fall into, and it can cause crashes. I'm a little worried that a note is something that people will skip over, or at least not fully mentally process. Is there an API for precedent you had in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where have you seen people fall into this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On GitHub, the two best examples off the top of my head are #125908 and #134289 (comment). It's a mistake I could definitely see some users of the C API making, but I'll be able to live with it as a note too.
The
PyMutex_IsLocked()
function is useful in assertions for verifying that code maintains certain locking invariants.PyMutex_IsLocked
in the public C API #134009📚 Documentation preview 📚: https://cpython-previews--134365.org.readthedocs.build/en/134365/c-api/init.html#c.PyMutex_IsLocked