[mod_python] handler module loading/execution phases

Graham Dumpleton graham.dumpleton at gmail.com
Tue Oct 13 07:15:03 EDT 2009


Apache/mod_python on UNIX is multi process and therefore requests
don't necessarily go back to the same process. Also, if using worker
MPM, that code isn't thread safe and so technically multiple threads
updating global variable at same time could not see it being
incremented as you expect.

It is also possible for Apache processes to be recycled both at the
whim of Apache, but also explicitly if MaxRequestsPerChild is set to
be non zero in Apache configuration files.

BTW, if you have PythonDebug set to On, then the error logs should
display messages about when mod_python loads or reloads mod_python
handler module files.

Graham

2009/10/13 Alessandro de Manzano <demanzano at playstos.com>:
> Hello,
>
> I'm using ModPyhton 3.3.1 with Apache 2.2.13 and I'm developing a simple
> RESTful-like custom webservice.
>
> All is working correctly, but I'm investigating some "optimization" issues.
>
> In particular, it's not clear to me when/how modpython (re)loads/(re)imports
> the handler's own .py module.
>
> I mean, something like that:
>
>
> testdummy.py:
>
> DUMMY = 0
>
> def handler(req):
>        global DUMMY
>        apache.log_error("dummy = %d" % DUMMY, apache.APLOG_ERR, req.server)
>        DUMMY += 1
>
>        [etc etc. simple req.write() etc.]
>
>
> "testdummy.py" is configured in Apache as PythonHandler:
>    [..]
>    AddHandler mod_python .py
>    PythonHandler testdummy
>    PythonDebug On # just for debug
>    PythonAutoReload On # just for debug
>
>
> I was expecting to see "dummy = n" where n > 0 sometime in the log.. As soon
> as the same apache process get executed again it should maintain the global
> variable, I tought.
> Since this does NOT happens (verified after about 100s requests) I guess the
> "testdummy.py" module is re-evaluated EVERY single time, for every and each
> request.
> I am right ? or where am I wrong ?
> I read the docs but apparently did not find a description of this issue
>
> Where can I read about the procedures/phases of module loading/evaulating of
> handlers ?
>
>
> Any hints is welcomed!
>
> Thanks in advance
>
>
> A. de Manzano
> Milano
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>



More information about the Mod_python mailing list