Skip to content

gh-145254: Add thread safety annotation#145255

Open
lysnikolaou wants to merge 1 commit intopython:mainfrom
lysnikolaou:thread-safety-annotation
Open

gh-145254: Add thread safety annotation#145255
lysnikolaou wants to merge 1 commit intopython:mainfrom
lysnikolaou:thread-safety-annotation

Conversation

@lysnikolaou
Copy link
Member

@lysnikolaou lysnikolaou commented Feb 26, 2026

  • Implement annotation for different thread safety levels
  • Annotate PyMutex_* APIs

📚 Documentation preview 📚: https://cpython-previews--145255.org.readthedocs.build/en/145255/c-api/synchronization.html#c.PyMutex_Lock

- Implement annotation for different thread safety levels
- Annotate PyMutex_* APIs
@hugovk
Copy link
Member

hugovk commented Feb 27, 2026

python/python-docs-theme#297 is merged and released in https://github.com/python/python-docs-theme/releases/tag/2026.2

Fix the lint with uvx prek run --all-files or uvx prek run --all-files ruff-format.

And as a bonus, the docs will rebuild with the new theme.

Comment on lines +304 to +315
_THREADSAFETY_DISPLAY = {
"incompatible": "Not safe to call from multiple threads.",
"compatible": "Safe to call from multiple threads with external synchronization only.",
"safe": "Safe for concurrent use.",
}

# Maps each thread safety level to the glossary term it should link to.
_THREADSAFETY_TERM = {
"incompatible": "thread-incompatible",
"compatible": "thread-compatible",
"safe": "thread-safe",
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this be backported?

Even if so, perhaps use frozendict on main?

Suggested change
_THREADSAFETY_DISPLAY = {
"incompatible": "Not safe to call from multiple threads.",
"compatible": "Safe to call from multiple threads with external synchronization only.",
"safe": "Safe for concurrent use.",
}
# Maps each thread safety level to the glossary term it should link to.
_THREADSAFETY_TERM = {
"incompatible": "thread-incompatible",
"compatible": "thread-compatible",
"safe": "thread-safe",
}
_THREADSAFETY_DISPLAY = frozendict(
incompatible = "Not safe to call from multiple threads.",
compatible = "Safe to call from multiple threads with external synchronization only.",
safe = "Safe for concurrent use.",
)
# Maps each thread safety level to the glossary term it should link to.
_THREADSAFETY_TERM = frozendict(
incompatible = "thread-incompatible",
compatible = "thread-compatible",
safe = "thread-safe",
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants