[mod_python] How to perform cleanup action when the python process dies?

Dan Eloff dan.eloff at gmail.com
Sat Jun 11 19:46:36 EDT 2005

I have global resources that persist as long as the process does
(database connections) but they could also be files or sockets or
other resources that need to be released. Python destructors are very
dicey from what I've heard, there seems no guarantee that the __del__
method on the connection pool will be called before the database
module is itself destroyed. I can't use req.register_cleanup() since
the objects stay alive across all the requests. When apache is
restarted though, how do I ensure the database connections were closed
on exit?

I saw a similar post to this on the list, but it just recommends not
to trust python destructors for important things like closing a
database connection.


More information about the Mod_python mailing list