[capi-sig] Register function to call at shutdown

Hrvoje Niksic hniksic at xemacs.org
Thu Jan 17 13:49:55 CET 2008


Is it possible to register a function to be called at finalization
time?  By finalization time I'm referring to the point at which Python
is still operational, but is shutting down, for example the time when
the modules are getting cleaned up.  Functions registered with
Py_AtExit get called too late, when it's no longer allowed to invoke
any Python API function.

I currently simulate this using an object whose __del__ invokes my
function, and sticking that object in a private module.  During module
cleanup Python unhooks the object from the module, firing its __del__
which calls my function.  But I consider it a hack, and a fragile one
at that -- if anyone deletes the object from the module, the function
will be called too early.  I'd prefer a cleaner way to deal with this
if possible.


More information about the capi-sig mailing list