cpython
cpython copied to clipboard
gh-118789: Add `PyUnstable_Object_ClearWeakRefsExceptCallbacks`
This exposes _PyWeakref_ClearWeakRefsExceptCallbacks
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.
- Issue: gh-118789
📚 Documentation preview 📚: https://cpython-previews--118807.org.readthedocs.build/