How to call cleanup code in a Python extension module

Markus Gritsch gritsch at iue.tuwien.ac.at
Thu Jun 21 10:38:42 EDT 2001


Hi!

I am writing an extension module in C and I need to make some
initializations when the module is loaded and some cleanup before exiting
the interpreter.  Initialization can be done in the extensions initxxx()
function, but I wonder where to put the cleanup code when the module is
unloaded since I have not found a delxxx() function.

Currently I a using a work-around by forcing the user to use a Python
class to communicate with the extension, and the initialization and
cleanup functions are called by the classes __init__() and __del__()
methods.  Anyway, if an exception occures, the cleanup code is not
executed.

Thanks for comments in advance,
Markus



More information about the Python-list mailing list