This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pablogsal
Recipients a-feld, deekay, pablogsal, tim.peters
Date 2020-04-20.15:59:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1587398373.16.0.74941403436.issue40312@roundup.psfhosted.org>
In-reply-to
Content
I think this is a good summary of what you are referring to:

>>> import gc, weakref
>>> class Lazarus:
...    def __del__(self):
...       global x
...       x = self
...
>>> def callback(*args):
...     print("DEAD")
...

# No gc dead:

>>> x = None
>>> a = Lazarus()
>>> w = weakref.ref(a, callback)
>>> del a # Notice that the callback has not been executed
>>> del x
DEAD

# Gc code:

>>> a = Lazarus()
>>> x = None
>>> cycle = []
>>> cycle.append(cycle)
>>> cycle.append(a)
>>> w = weakref.ref(a, callback)
>>> del a,cycle
>>> gc.collect()
DEAD
>>> x. #The callback has executed but the variable is still alive
<__main__.Lazarus object at 0x1020e9910>


The "problem" is that when going through the gc, the callback is executed when the object is resurrected but going through normal refcount the callback is executed only when the object dies.

Notice that in both cases the fundamental property still holds: the callback is executed *once*. What you are discussing now is a matter of *when*. 

Not sure if we want to homogenize both code paths, but changing the one that goes through the GC is going to be challenging to say the least because as Tim mentioned, the weakrefs semantics are *very* delicate.
History
Date User Action Args
2020-04-20 15:59:33pablogsalsetrecipients: + pablogsal, tim.peters, a-feld, deekay
2020-04-20 15:59:33pablogsalsetmessageid: <1587398373.16.0.74941403436.issue40312@roundup.psfhosted.org>
2020-04-20 15:59:33pablogsallinkissue40312 messages
2020-04-20 15:59:33pablogsalcreate