Understanding WSGI together with Apache

dieter dieter at handshake.de
Sun Oct 11 01:46:22 EDT 2015


Johannes Bauer <dfnsonfsduifb at gmx.de> writes:
> I'm running an Apache 2.4 webserver using mod_wsgi 4.3.0. There are two
> different applications running in there running on two completely
> separate vhosts.
>
> I'm seeing some weird crosstalk between them which I do not understand.
> In particular, crosstalk concerning the locales of the two. One
> application needs to output, e.g., date information using a German
> locale. It uses locale.setlocale to set its LC_ALL to de_DE.UTF-8.
>
> Now the second application doesn't need nor want to be German. It wants
> to see the C locale everywhere, in particular because at some point it
> uses datetime.datetime.strptime() to parse a datetime.
>
> Here's where things get weird: Sometimes, my "C" locale process throws
> exceptions, because it's unable to parse a date. When looking why this
> fails, the string looks like de_DE's "Sa, 10 Okt 2015" instead of C's
> "Sat, 10 Oct 2015". This seems to happen depending on which worker
> thread is currently serving the request, i.e. nondeterministically.

This is more an Apache than a Python question.

The "locale" implementation does not expect different "locale"s
in the same process (this is true not only on the Python but also
on the "C" level). Thus, if in a single process, two concurrent
activities (i.e. threads) need different "locale"s, you are in trouble.

Your problem discription indicates that something like this is
happening in your WSGI setup.


I suppose that a single Python process is not used to process
several requests at the same time (but I may be wrong). In this
case, you have a chance to set the correct locale for the current
request processing at request start. If, however, a single Python
process is used for all requests and concurrent requests are handled
by separate tasks, then there is no safe way to get the "locale" right.

At your place, I would search the Apache documentation related to
"mod_wsgi" to find out how it uses processes and tasks for request processing.




More information about the Python-list mailing list