[issue38006] Crash in remove() weak reference callback of weakref.WeakValueDictionary at Python exit

Tim Peters report at bugs.python.org
Fri Sep 27 23:59:19 EDT 2019


Tim Peters <tim at python.org> added the comment:

tp_clear implementations are necessary to reclaim trash cycles.  They're always best practice for objects that may be in trash cycles.   tuples are just "cute rebels" that way ;-)

Best guess is that the (some) extension isn't playing by the rules.  A weakref callback shouldn't be called at all unless the weakref is reachable - but in that case the callback function is necessarily reachable too (revealed by a weakrefobject's tp_traverse), so delete_garbage() should never have called clear() on the callback function to begin with.

Note:  I don't believe the weakref design gave any thought to cyclic gc.  The PEP didn't even mention it.  I got dragged into it when Zope started segfaulting.  They don't play well together voluntarily, but they've been forced to coexist, and Zope long ago provoked every fundamental problem I'm aware of.

That "the rules" are subtle doesn't excuse not following them ;-)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38006>
_______________________________________


More information about the Python-bugs-list mailing list