[Python-ideas] breaking cycles that include __del__

Daniel Stutzbach daniel at stutzbachenterprises.com
Mon Oct 19 16:25:08 CEST 2009

On Sat, Oct 17, 2009 at 11:17 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> The gist is that you split your object into a "core" which requires
> finalisation (but can never itself be caught up in a cycle) and the main
> object which may participate in cycles. A weak reference to the main
> object is placed in a global container. When the weak reference callback
> is invoked, the object core is still in a valid state so it can be
> finalised safely, even though the main object may be in the midst of
> cycle collection.
> This recipe gives a pretty good idea of how that approach works:
> http://code.activestate.com/recipes/519610/

That idiom (and that recipe in particular! yuck!) is pretty convoluted, IMO.

Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20091019/7d237d1b/attachment.html>

More information about the Python-ideas mailing list