On Sep 5, 6:54 am, Petr Tuma <cere...@gmail.com> wrote:
> One more note, just if somebody else runs into this.
>
> Apparently, the problem with this solution is that under certain
> conditions, SetEnv from one virtual host can be visible inside the
> Python interpreter associated with another virtual host. Since
> mod_python suggests not to use SetEnv, one should probably not be
> surprised all that much.
>
> A working solution is to branch on something else than the environment
> variable in urls.py. Using apache.interpreter imported from mod_python
> seems to work just fine.

It should be pointed at that the leakage of environment variables
between sub interpreters is not actually mod_python's fault. It is a
combination of an issue with Python itself triggered by what the
mod_python handler for Django does. In other words, not the fault of
mod_python itself.

The underlying issue is that when os.environ is set, this triggers a
call of putenv() in C library to promote the variable to a process
wide variable. A Python sub interpreter created after that point, will
have that environment variable copied into its os.environ.

Normally, for SetEnv directive this wouldn't make the least bit of
difference because SetEnv directive normally doesn't promote the set
values to process wide environment variables in the Apache server
child processes themselves. Normally they would only be set up in sub
processes created specifically for CGI scripts.

The table of such SetEnv variables is though still available to
mod_python, but in a distinct data structure. Django unwisely copies
those variables in its mod_python handler and promotes them to process
wide environment variables. This was done so that SetEnv could be used
to set DJANGO_SETTINGS_MODULE.

Django should really only have promoted that single variable and
better still should never have relied on process environment variables
to begin with. Unfortunately, not something that can easily be changed
now.

Anyway, you will not have an issue if instead of using differently
named environment variables for each site, you use the same
environment variable name and just set them different. That is, use
the value of the single environment variable to distinguish rather
than the name of the variable.

Better still, stop using mod_python. Instead, use mod_wsgi and its
daemon mode to separate the two instances in completely different
processes and therefore never risk environment variable leakage or any
of the other issues arising from running multiple Python web
applications in different sub interpreters of the same process.

Graham
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to