[Python-Dev] Proposal: standard way of defining and executing "atexit" functions...

David Ascher DavidA@ActiveState.com
Mon, 19 Jun 2000 14:12:03 -0700


> If someone fails to use the defined protocol, screw 'em... ;-)

That's unreasonable given that existing tools might include a library which
might be upgraded to use the new mechanism while the old code used its own
mechanism happily.  For example, I've used my own protocols in the past
which went something like...

def register_exitfunc(func):
    old_exitfunc = getattr(sys, 'exitfunc', None)
    def wrapper(old_exitfunc=old_exitfunc, new_func=func):
      if old_exitfunc is not None: old_exitfunc()
      new_func()
    sys.exitfunc = wrapper

or some such, creating a call chain instead of a sequence of calls, and it's
a 'fine' protocol in that it worked fine in the absence of a standard.  No
need to break code if we can avoid it.

The point of my pseudo-patch, if it wasn't clear, was that if a function is
already in sys.exitfunc, then it should still be called on exit after the
new exit module is imported.  You're right that my patch didn't properly
check that _run_exitfuncs might be that function.

--david