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

Stefan Richthofer stefan.richthofer at gmx.de
Mon Oct 27 16:20:06 CET 2014

 >It's not that resurrection occurs indirectly, it's that the object
 >pointed to by "x2" always remains alive

Yes, this is right for CPython, more precisely this is about the definition
of the word "resurrection" (in language-independent sense),
which seems not to be unique.

I already pointed out
"One can surely argue x2 has never been dead, or see it as
"it was killed along with x and then resurrected by x"."

In Java and thus in Jython, it is treated as the second one. An equal
program written in Java or Jython would even call the finalizer of x2 (if
it had one) and clear weakrefs before it is available "again" as a class
attribute of X.
So there actually *is* a notion to refer to this scenario as resurrection.
I admit it is arguable and maybe misleading in CPython case and I was
not aware of the whole behavior when I called the topic "resurrection".

What would still be interesting (at least when Jython 3 is born),
is which of the mentioned behaviors occurs if it is
performed by CPython's cyclic gc (consistently the first one I would guess).
As you pointed out, this is only relevant from 3.4 on since in 2.x etc 
it does
not call finalizers in cycles. (Since I mainly work on Jython or Python 
2.7 I
currently have no 3.4 installed to test this instantaneously. I will 
test it someday...)



On 10/27/2014 03:14 PM, Antoine Pitrou wrote:
> 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*).
> Regards
> Antoine.
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/stefan.richthofer%40gmx.de

More information about the Python-Dev mailing list