Skip to content

Conversation

miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Jun 18, 2024

This exposes PyUnstable_Object_ClearWeakRefsNoCallbacks as an unstable
C-API function to provide a thread-safe mechanism for clearing weakrefs
without executing callbacks.

Some C-API extensions need to clear weakrefs without calling callbacks,
such as after running finalizers like we do in subtype_dealloc.
Previously they could use _PyWeakref_ClearRef on each weakref, but
that's not thread-safe in the free-threaded build.

(cherry picked from commit e8752d7)

Co-authored-by: Sam Gross [email protected]
Co-authored-by: Petr Viktorin [email protected]


📚 Documentation preview 📚: https://cpython-previews--120695.org.readthedocs.build/

…thonGH-118807)

This exposes `PyUnstable_Object_ClearWeakRefsNoCallbacks` as an unstable
C-API function to provide a thread-safe mechanism for clearing weakrefs
without executing callbacks.

Some C-API extensions need to clear weakrefs without calling callbacks,
such as after running finalizers like we do in subtype_dealloc.
Previously they could use `_PyWeakref_ClearRef` on each weakref, but
that's not thread-safe in the free-threaded build.

(cherry picked from commit e8752d7)

Co-authored-by: Sam Gross <[email protected]>
Co-authored-by: Petr Viktorin <[email protected]>
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