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

Armin Rigo arigo at tunes.org
Sun Oct 26 18:44:53 CET 2014


Hi Stefan,

On 26 October 2014 02:50, Stefan Richthofer <Stefan.Richthofer at gmx.de> wrote:
> It appears weakrefs are only cleared if this is done by gc (where no
> resurrection can happen anyway). If a resurrection-performing-__del__ is
> just called by ref-count-drop-to-0, weakrefs persist -

How do you reach this conclusion?  The following test program seems to
show the opposite, by printing None on Python 2.7.6:

    import weakref
   class X(object):
        def __del__(self):
            print ref()
    x = X()
    ref = weakref.ref(x)
    del x


A bientôt,

Armin.


More information about the Python-Dev mailing list