[mod_python] mod_python modifies time zone of Apache child

Graham Dumpleton graham.dumpleton at gmail.com
Thu Aug 6 19:33:08 EDT 2009


2009/8/7 Stephan Paukner <paux at paukner.cc>:
> Hi,
>
> I use Apache2 in MPM prefork mode. I noticed that if a specific Apache
> child process handles a request to a roundup(.sf.net) tracker instance
> via mod_python, the child's time zone is set to UTC, permanently. If any
> other HTTP client gets to reuse that specific Apache child, the request
> is still handled in UTC. This leads to times jumping between UTC and the
> local timezone e.g. in a PHP-based calendar on the same site, depending
> on the involved Apache child processes, what is quite annoying.
>
> If I request the following URL sequence after an Apache restart:
>    https://ourhostname/server-status
>    https://ourhostname/tracker/
>    https://ourhostname/server-status
> then the "Current Time" indicated in the server-status shows e.g.
> "03:13:37 CEST" (our local timezone) before and "01:13:37 UTC"
> afterwards, because all three requests are obviously served by the same
> Apache child. These jumping times also show up in the Apache logs.
>
> This doesn't happen if I directly access the tracker via
>    http://ourhostname:8080/tracker/
>
> I tried adding
>    SetEnv TZ Europe/Vienna
> at various places in our virtual host, but AFAIK these settings are only
> read at the creation of a child process, not repeatedly. I don't know
> how to set the timezone globally for all python instances on that host;
> I set TZ in /etc/environment. I've set up the mod_python.testhandler
> like suggested in the Troubleshooting section, and /mpinfo indeed shows
> "TZ" with value "Europe/Vienna", but I can't see any time information in
> that output.
>
>
> All packages are from Debian amd64 Lenny. mod_python bindings for
> roundup are just as suggested
> in /usr/share/doc/roundup/examples/roundup_apache.
>
>
> Any suggestions on how to explore this further? Do you need more config
> info?

The PHP and Python applications run in the same process and TZ is a
process global setting so it is obvious that this will occur. Similar
issues will occur with locale and language settings.

The only answer is you can't run them in the same process which for
mod_php/mod_python means you cannot run them on the same Apache
instance.

Your only options are to bump PHP out to separate fastcgi process, or
use mod_wsgi instead of mod_python and use mod_wsgi daemon mode to
delegate the Python web application out to a separate process.

Graham



More information about the Mod_python mailing list