Reliably call code after object no longer exists or is "unreachable"?

Gregory Ewing greg.ewing at
Thu Apr 28 03:13:47 EDT 2011

Jack Bates wrote:

> Python's __del__ or destructor method works (above) - but only in the
> absence of reference cycles (below). An object, with a __del__ method,
> in a reference cycle, causes all objects in the cycle to be
> "uncollectable".

Store a weak reference to the object somewhere with a
callback. This should work even in the presence of
cycles, as long as the weak reference itself isn't
part of the cycle.


More information about the Python-list mailing list