cpython icon indicating copy to clipboard operation
cpython copied to clipboard

gh-118789: Add `PyUnstable_Object_ClearWeakRefsExceptCallbacks`

Open colesbury opened this issue 3 months ago • 7 comments

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/

colesbury avatar May 08 '24 22:05 colesbury