osdir.com

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


On Saturday, October 25, 2014, Stefan Richthofer <Stefan.Richthofer at gmx.de>
wrote:

> Okay, sorry, I was thinking too Jython-like. I fixed runGC() just to
> see now that it does not even trigger resurrection, since under
> CPython there are no finalizers executed in ref cycles (i.e. I find my
> objects in gc.garbage).
> So I realize, my xy_cyclic tests are pointless anyway since in cyclic
> gc no resurrection can happen.
>
> > The second problem (with weakref) is different: weakrefs are cleared
> > before __del__ is called, so resurrection doesn't affect the whole
> > process.
> 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 - a behavior that is
> very difficult and inefficient to emulate in Jython, but I'll give it
> some more thoughts...
>
> You shouldn't have to emulate that. The exact behavior of GC is allowed to
vary between systems.


> However thanks for the help!
>
> -Stefan
>
>
> > Gesendet: Sonntag, 26. Oktober 2014 um 01:22 Uhr
> > Von: "Antoine Pitrou" <solipsis at pitrou.net <javascript:;>>
> > An: python-dev at python.org <javascript:;>
> > Betreff: Re: [Python-Dev] results of id() and weakref.getweakrefs()
> sometimes break on object resurrection
> >
> >
> > Hello Stefan,
> >
> > On Sun, 26 Oct 2014 00:20:47 +0200
> > "Stefan Richthofer" <Stefan.Richthofer at gmx.de <javascript:;>> wrote:
> > > Hello developers,
> > >
> > > I observed strange behaviour in CPython (tested in 2.7.5 and 3.3.3)
> > > regarding object resurrection.
> >
> > Your runGC() function is buggy, it does not run the GC under CPython.
> > Fix it and the first problem (with id()) disappears.
> >
> > The second problem (with weakref) is different: weakrefs are cleared
> > before __del__ is called, so resurrection doesn't affect the whole
> > process. Add a callback to the weakref and you'll see it is getting
> > called.
> >
> > In other words, CPython behaves as expected. Your concern is
> > appreciated, though.
> >
> > Regards
> >
> > Antoine.
> >
> >
> > _______________________________________________
> > Python-Dev mailing list
> > Python-Dev at python.org <javascript:;>
> > https://mail.python.org/mailman/listinfo/python-dev
> > Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/stefan.richthofer%40gmx.de
> >
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org <javascript:;>
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/guido%40python.org
>


-- 
--Guido van Rossum (on iPad)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20141025/e36204cf/attachment.html>