[Python-Dev] results of id() and weakref.getweakrefs() sometimes break on object resurrection

Antoine Pitrou solipsis at pitrou.net
Mon Oct 27 15:14:22 CET 2014

On Mon, 27 Oct 2014 14:36:31 +0100
Stefan Richthofer <stefan.richthofer at gmx.de> wrote:
> Your test program performs no resurrection of x.
> Interestingly, it does not change behavior if you write
> class X(object):
>      def __del__(self):
>          X.x = self
>          print ref()
> (Thanks for making me aware of this! My test-case was already
> initially the more complex one given below)
> But if the resurrection occurs indirectly, the weakref persists:

It's not that resurrection occurs indirectly, it's that the object
pointed to by "x2" always remains alive (first as an instance attribute
of x, second as a class attribute of X *before x is deleted*).



More information about the Python-Dev mailing list