Title: Thread safety of PyCapsule · Issue #145563 · python/cpython · GitHub
Open Graph Title: Thread safety of PyCapsule · Issue #145563 · python/cpython
X Title: Thread safety of PyCapsule · Issue #145563 · python/cpython
Description: Bug report Bug description: The PyCapsule object is not thread-safe. For example the read and write operations to the underlying pointer do not use atomics. cpython/Objects/capsule.c Line 111 in e094544 return capsule->pointer; This can ...
Open Graph Description: Bug report Bug description: The PyCapsule object is not thread-safe. For example the read and write operations to the underlying pointer do not use atomics. cpython/Objects/capsule.c Line 111 in e0...
X Description: Bug report Bug description: The PyCapsule object is not thread-safe. For example the read and write operations to the underlying pointer do not use atomics. cpython/Objects/capsule.c Line 111 in e0...
Opengraph URL: https://github.com/python/cpython/issues/145563
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Thread safety of PyCapsule","articleBody":"# Bug report\n\n### Bug description:\n\nThe `PyCapsule` object is not thread-safe. For example the read and write operations to the underlying `pointer` do not use atomics.\n\nhttps://github.com/python/cpython/blob/e0945443a0abdee56a51a5cb82a31edba5f1adab/Objects/capsule.c#L111\n\nThis can be fixed with atomic read and write operations. (same for the `name` field and some others)\n\nAnother potential issue is that some operations on a capsule are not atomic. For example a thread can attempt to retrieve a pointer using `PyCapsule_GetPointer` while a concurrent thread is updating the name and pointer using `PyCapsule_SetName` and `PyCapsule_SetPointer`. That could be addressed with locks, but I suspect that is too heavy for the capsule object.\n\nI am leaning towards adding atomics for the read and write operations and documenting that in a PyCapsule does not guarantee its methods are atomic.\n\n@colesbury @seberg \n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nWindows\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-146612\n* gh-146659\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/eendebakpt","@type":"Person","name":"eendebakpt"},"datePublished":"2026-03-05T18:07:21Z","url":"https://github.com/python/cpython/issues/145563"}
| 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:a958cac0-68f8-96e2-48e3-dbc003ff3651 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DE80:F7C4C:34479DB:45FDA1E:6B020972 |
| html-safe-nonce | d9d7b5fc93394430353eab9373a759a5249805425123a5d3a20667b26dd7238a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERTgwOkY3QzRDOjM0NDc5REI6NDVGREExRTo2QjAyMDk3MiIsInZpc2l0b3JfaWQiOiI0Mzc1NDI3Mzg5NzU3NDU4ODAyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b9b6a547d4c0be325d5ed1108e4b3ee25f1e6a4f51370d691e889e175d4e2fe0 |
| hovercard-subject-tag | issue:4029801169 |
| 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/145563/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6a4a80251601f13fae232310d44824b44d8b93ae035130095699c31ea8f53eaf/python/cpython/issues/145563 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6a4a80251601f13fae232310d44824b44d8b93ae035130095699c31ea8f53eaf/python/cpython/issues/145563 |
| og:image:alt | Bug report Bug description: The PyCapsule object is not thread-safe. For example the read and write operations to the underlying pointer do not use atomics. cpython/Objects/capsule.c Line 111 in e0... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | eendebakpt |
| 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