[Python-Dev] atexit missing an unregister method

Raymond Hettinger python at rcn.com
Mon Apr 25 22:25:50 CEST 2005

[Nick Jacobson]
> I was looking at the atexit module the other day; it seems like an
> way to ensure that resources are cleaned up (that the garbage
> doesn't take care of).
> But while you can mark functions to be called with the 'register'
> there's no 'unregister' method to remove them from the stack of
> to
> be called.  
 . . .
> Alternatively, it would be great if there were a way to view the stack
> registered functions, and delete them from there.

Please file a feature request on SourceForge.

Will mull it over for a while.  My first impression is that try/finally
is a better tool for the scenario you outlined.  

The issue with unregister() is that the order of clean-up calls is
potentially significant.  If the same function is listed more than once,
there would be no clear-cut way to know which should be removed when
unregister() is called.

Likewise, I suspect that exposing the stack will create more pitfalls
and risks than it could provide in benefits.  Dealing with a stack of
functions is likely to be clumsy at best.

Raymond Hettinger

More information about the Python-Dev mailing list