[Python-ideas] breaking cycles that include __del__

Adam Olsen rhamph at gmail.com
Tue Oct 20 23:58:05 CEST 2009

On Tue, Oct 20, 2009 at 11:59, Scott Dial
<scott+python-ideas at scottdial.com> wrote:
> The only way to guarantee the callback occurs is if you attach it to
> some other object that will outlive your object, *but* must also not get
> pulled into the same gc generation, otherwise it will *still not be
> called*. I believe this is the source of your advice to store the
> weakref in some globally reachable set. I believe given the way modules
> are currently deallocated, this is guaranteed to work. Should modules
> ever be included in the gc, then perhaps this would have to be revisited.

Right, but if you want to guarantee your method will be called on
shutdown it's better to fall back on an atexit handler.  Once we start
tearing down modules we can't promise any sane state, so it'd be
better to disable weakref callbacks entirely.

Adam Olsen, aka Rhamphoryncus

More information about the Python-ideas mailing list