You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This can be fixed with atomic read and write operations. (same for the name field and some others)
Another 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.
I am leaning towards adding atomics for the read and write operations and documenting that in a PyCapsule does not guarantee its methods are atomic.
Activity
colesbury commentedon Mar 5, 2026
It seems fine to me to require that callers to the capsule API are required to do their own synchronization.
eendebakpt commentedon Mar 5, 2026
To be clear: does that mean we also do not add atomic reads/writes to the
pointerinPyCapsule_GetPointer?colesbury commentedon Mar 5, 2026
Yes
aisk commentedon Mar 6, 2026
Should we update the document to include a thread-safety notice for users, if we want callers to ensure thread safety?
encukou commentedon Mar 11, 2026
#145255 will add a mechanism for thread safety notices.
gh-145563: Add thread-safety annotation for PyCapsule C-API (#146612)
pythongh-145563: Add thread-safety annotation for PyCapsule C-API (py…
[3.14] gh-145563: Add thread-safety annotation for PyCapsule C-API (G…
pythongh-145563: Add thread-safety annotation for PyCapsule C-API (py…
pythongh-145563: Add thread-safety annotation for PyCapsule C-API (py…