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

Dan Stromberg drsalists at gmail.com
Thu Apr 28 03:11:57 CEST 2011


On Wed, Apr 27, 2011 at 5:54 PM, Thomas 'PointedEars' Lahn <
PointedEars at web.de> wrote:

> Jack Bates wrote:
> > Faced with the real potential for reference cycles, how can you reliably
> > call code - but wait until an object no longer exists or is
> > "unreachable"?
>
> For normal program termination, the solution is the `atexit' module (as
> used
> e.g. in <
> http://code.activestate.com/recipes/523007-semi-automatic-resource-
> management-with-autoclose/>, however it is considered better style to
> explicitly call methods that free resources, and `del' object references.
>
> As for abnormal program termination, I think there is no way to deal with
> signals that signal.signal() cannot handle.
>

Sometimes __enter__, __exit__ and "with" combine well for such a purpose,
depending on what the actual purpose is.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110427/21cd21af/attachment.html>


More information about the Python-list mailing list