Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add thread safety annotations for C API functions #145254

Copy link
Copy link
@lysnikolaou

Description

@lysnikolaou
Issue body actions

Documentation

CPython's C API documentation has no systematic way to communicate the thread safety guarantees of individual APIs. As the free-threaded build matures, this information is increasingly important for extension authors.

This is analogous to how return value ownership is documented today, with automatically-inserted "Return value: New reference." / "Return value: Borrowed reference." annotations. We should do the same for thread safety.

Proposed levels

Three levels, ordered from least to most safe:

  • Thread-incompatible: Not safe even with external locking
  • Thread-compatible: Safe if the caller serializes all access with external locks
  • Safe: Safe to call from multiple threads on shared objects

Each annotation links to the corresponding glossary term. The thread-safe term already exists in the glossary, thread-compatible and thread-incompatible would be added.

I have PRs ready for both CPython and python-docs-theme. Feedback welcome, especially on the choice and naming of levels.

Linked PRs

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    Status
    Todo
    Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.