Skip to content

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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

colesbury
Copy link
Contributor

@colesbury colesbury commented May 20, 2025

The PyMutex_IsLocked() function is useful in assertions for verifying that code maintains certain locking invariants.


📚 Documentation preview 📚: https://cpython-previews--134365.org.readthedocs.build/en/134365/c-api/init.html#c.PyMutex_IsLocked

The `PyMutex_IsLocked()` function is useful in assertions for verifying
that code maintains certain locking invariants.
Co-authored-by: Kumar Aditya <kumaraditya@python.org>

Returns non-zero if the mutex *m* is currently locked, zero otherwise.

.. note::
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

@ZeroIntensity ZeroIntensity May 28, 2025

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?

Copy link
Contributor Author

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?

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants