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 Anssi.Kääriäinen
Recipients Anssi.Kääriäinen, amaury.forgeotdarc, benjamin.peterson, docs@python, isoschiz, ncoghlan, pconnell, pitrou, vstinner
Date 2013-04-20.12:19:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1366460372.15.0.650901872155.issue17468@psf.upfronthosting.co.za>
In-reply-to
Content
I was imagining that the collection should happen in two passes. First check for tp_dels and call them if safe (single tp_del in cycle allowed). Then free the memory. The first pass is already there, it just doesn't collect callable tp_dels.

If it would be possible to turn an object into inaccessible state after tp_del was called it would be possible to call multiple tp_dels in a cycle. If the del tries to use already deleted object you will get some sort of runtime exception indicating access of already collected object (another option is to allow access to object which has already had __del__ called, but that seems problematic).

Now, both of the above are likely way more complicated to implement than what I imagine. I have very little knowledge of the technical details involved.

If I understand correctly your idea was to do something similar to above, but only for generators.

The current situation is somewhat ugly. First, I can imagine people wishing to do try-finally or something "with self.lock:" in a generator. These will leak in circular reference cases. The generator case is surprising, so surprising that even experienced programmers will do such mistakes (see the django ticket for one example). Second, from application programmers perspective the fact that __del__ wasn't called is usually similar to having a silent failure in their code - for example this can result in leaking database connections or other resources, not to mention possible problems if one has a "with self.lock:" block in a generator.
History
Date User Action Args
2013-04-20 12:19:32Anssi.Kääriäinensetrecipients: + Anssi.Kääriäinen, amaury.forgeotdarc, ncoghlan, pitrou, vstinner, benjamin.peterson, docs@python, pconnell, isoschiz
2013-04-20 12:19:32Anssi.Kääriäinensetmessageid: <1366460372.15.0.650901872155.issue17468@psf.upfronthosting.co.za>
2013-04-20 12:19:32Anssi.Kääriäinenlinkissue17468 messages
2013-04-20 12:19:31Anssi.Kääriäinencreate