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

Tim Peters report at bugs.python.org
Tue Oct 1 14:29:30 EDT 2019


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

Neil, about this comment:

#   - ct is not yet trash (it actually is but the GC doesn't know because of
#     the missing tp_traverse method).

I believe gc should know ct is trash.  ct is in the cf list, and the latter does have tp_traverse.

What gc won't know is that `a` is trash, because `a` is attached to ct, and ct doesn't have tp_traverse.

It should blow up anyway :-)

Maybe with a simpler structure it would be easier to rearrange code to nudge the callback into getting cleared before use?

Z <- Y <- A <-> B -> WZ -> C

where WZ is a weakref to Z with callback C, and Y doesn't implement tp_traverse.  The only cycle is between A and B, which could just as well be the same object.  All the other stuff hangs off that cycle.

It's all trash, but we won't know in advance that Z is part of it.

----------

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


More information about the Python-bugs-list mailing list