[mod_python] server shutdown [was] i beg...

Richard Lewis richardlewis at fastmail.co.uk
Fri Aug 18 05:48:52 EDT 2006

On Tuesday 15 August 2006 23:31, Graham Dumpleton wrote:
> Richard Lewis wrote ..
> >
> > Do you mean that there will be no opportunity to have code run at server
> > shutdown?
> Correct. Reason being that it doesn't actually work most of the time
> anyway.
> Because of how Apache is implemented, there is no reliable/safe way of
> implementing this feature. If one can't do it properly, it seems better not
> to attempt it at all.
Goodness! So, in my mod_python applications I often acquire database handles 
and store them in objects outside of the handler() function so that they 
persist between requests. (This is to avoid the expense of acquiring a new 
handle for every request). I then use a cleanup() function to release those 
database handles.

The implication of this is that I will no longer be able to release the 
handles at server shutdown, yes? Can anyone suggest an alternative method of 
doing this? Are there any Python tricks where you can execute code when the 
interpreter itself is about to stop? Or could I have a Python script running 
in another process which "looks in" to the mod_python process and 
periodically cleanly releases database handles?

Richard Lewis
Sonic Arts Research Archive
JID: ironchicken at jabber.earth.li

More information about the Mod_python mailing list