[mod_python] i beg the developers to make mod_python can beimport in python command line.

Graham Dumpleton grahamd at dscpl.com.au
Tue Aug 15 18:31:40 EDT 2006


Richard Lewis wrote ..
> On Tuesday 15 August 2006 11:01, you wrote:
> > On 15/08/2006, at 6:53 PM, Richard Lewis wrote:
> > > class server:
> > >     def __init__(self):
> > >         self.cleanup_func = None
> > >         self.server_hostname = ""
> > >
> > >     def register_cleanup(self, req, func):
> > >         self.cleanup_func = func
> >
> > Be aware that req.server.register_cleanup() doesn't really work
> > properly and
> > is going to be disabled in mod_python 3.3 such that it doesn't do
> > anything.
> > A stub will still be there so your code at least still runs, but no
> > special actions
> > will performed on server shutdown.
> >
> 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.

The basic problem is that those server cleanups are being run from inside of a
signal handler. If there is any active request occurring which is being handled
by mod_python at the time that shutdown occurs, or if the code has created
separate Python threads which are running at the time, then the cleanup code
actually deadlocks as the Python code which was already running is holding the
interpreter lock and the cleanup code can't acquire it.

The end result is that the whole child process hangs and the parent process
noticing this, keeps trying to send more SIGTERM's and after that still does
not work, it sends a SIGKILL and simply kills the process. In the worst cases
the child processes don't even hang, they simply crash, because Python code
is in no way signal safe anyway.

Thus, although you might see it working okay if your server is lightly loaded,
and you are lucky, if it handles any amount of traffic, this features tends not
to work at all and simply causes problems/delays on trying to do timely
restarts of Apache.

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.

Graham


More information about the Mod_python mailing list