Title: Add thread safety annotations for C API functions · Issue #145254 · python/cpython · GitHub
Open Graph Title: Add thread safety annotations for C API functions · Issue #145254 · python/cpython
X Title: Add thread safety annotations for C API functions · Issue #145254 · python/cpython
Description: 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 ...
Open Graph Description: 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 increasingl...
X Description: 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 increas...
Opengraph URL: https://github.com/python/cpython/issues/145254
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add thread safety annotations for C API functions","articleBody":"### Documentation\n\nCPython'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.\n\nThis 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.\n\n#### Proposed levels\n\nThree levels, ordered from least to most safe:\n\n- **Thread-incompatible**: Not safe even with external locking\n- **Thread-compatible**: Safe if the caller serializes all access with external locks\n- **Safe**: Safe to call from multiple threads on shared objects\n\nEach annotation links to the corresponding glossary term. The `thread-safe` term already exists in the glossary, `thread-compatible` and `thread-incompatible` would be added.\n\nI have PRs ready for both CPython and python-docs-theme. Feedback welcome, especially on the choice and naming of levels.\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-145255\n* gh-145862\n* gh-146111\n* gh-146163\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/lysnikolaou","@type":"Person","name":"lysnikolaou"},"datePublished":"2026-02-26T13:35:06Z","url":"https://github.com/python/cpython/issues/145254"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4a91e794-c599-4206-99f9-6076b6d8ceb2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D1F0:399E4B:375B439:4970017:6B020208 |
| html-safe-nonce | bc725e43fea825b8a6df09a8285361eb9c2739437e2d0adbeb6a22c019b3f50c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMUYwOjM5OUU0QjozNzVCNDM5OjQ5NzAwMTc6NkIwMjAyMDgiLCJ2aXNpdG9yX2lkIjoiODY5MzE3NDU5NTI5NDk4Njc2MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f8274635c8046ed646fb8f81d9d679f644b8df060a353c05e56a7dde366e17a3 |
| hovercard-subject-tag | issue:3995616758 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/145254/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7f8cdf042713514ae55b7d0a67e7fc8ae93e27462a04718c206d31ee40a95d02/python/cpython/issues/145254 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7f8cdf042713514ae55b7d0a67e7fc8ae93e27462a04718c206d31ee40a95d02/python/cpython/issues/145254 |
| og:image:alt | 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 increasingl... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | lysnikolaou |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width