How to call cleanup code in a Python extension module

M.-A. Lemburg mal at lemburg.com
Thu Jun 21 11:49:00 EDT 2001


Skip Montanaro wrote:
> 
>     Markus> ... I wonder where to put the cleanup code when the module is
>     Markus> unloaded since I have not found a delxxx() function.
> 
> Take a look at the C atexit(3) library function.  Note that it will only get
> called if your program terminates by a call to exit(3), which may not be the
> case when an exception is raised.

Python allows you to register atexit() like functions which are
executed when Python exits (see e.g. the source code of mxDateTime
for an example).

Note that unloading of extensions at runtime is not supported by 
Python. This would require DLL unloading which is not implemented
in a platform independent way (it probably could be done, though).

As always: patches are welcome :-)

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Consulting & Company:                           http://www.egenix.com/
Python Software:                        http://www.lemburg.com/python/




More information about the Python-list mailing list