[mod_python] Child shutdowns?

Greg Stein gstein at lyra.org
Fri Aug 29 15:23:28 EST 2003


On Fri, Aug 29, 2003 at 06:05:31PM -0400, Barry Warsaw wrote:
> On Fri, 2003-08-29 at 17:47, Barry Warsaw wrote:
> 
> > Thanks Grisha, both for the info and the offer to poke around.  I'll try
> > pushing my startup code into my request handler, and see if registering
> > my cleanup code at that time will work.
> 
> Very quick testing reveals that something like this stanza does the
> trick:
> 
> def handler(req):
>     global _started
>     if not _started:
>         startup()
>         req.server.register_cleanup(req, shutdown)
>         _started = True
> 
> A bit gnarly perhaps, but palatable.

Ouch! The interface is very non-intuitive. That is not a cleanup
associated with the server, but actually with the pchild pool that was
passed to the child_init hook.

Looking at the code, mod_python hooks into child_init and saves the pool
off into a global variable. The server_register_cleanup() function then
attaches the cleanup to *that* pool.

So it does what you want, but yah... a bit ugly. And it really doesn't
look thread-safe either. You could easily have two threads end up inside
the 'if' block, registering a cleanup.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/


More information about the Mod_python mailing list