Re: Same application with different URLs

2009-09-05 Thread Graham Dumpleton



On Sep 5, 6:54 am, Petr Tuma  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
-~--~~~~--~~--~--~---



Re: Same application with different URLs

2009-09-04 Thread Petr Tuma

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.

Petr

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Same application with different URLs

2009-09-04 Thread Petr Tuma

Hi Andrew,

> What is the error 500?  Is it the same error every time?

I did not find any details in the logs and with DEBUG = True, the site
starts behaving correctly.

> Also, you have restarted apache?  Different apache processes could be
> out of sync and running different django configs, thus giving
> different outcomes.

Yes, to no avail.

After half a day of experimenting, it looks like using the
transactional middleware to make a separate transaction for every
request was what was needed (still testing to make sure everything
works, but I did not see the error for some time now.

Thanks, Petr

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Same application with different URLs

2009-09-04 Thread Andrew McGregor

> strangely unreliable. When both sites are used, an Error 500: Internal
> server error is frequently returned (but mere repeated reloading of
> the same page eventually gives a correct page).

What is the error 500?  Is it the same error every time?

Also, you have restarted apache?  Different apache processes could be
out of sync and running different django configs, thus giving
different outcomes.

-- 
Andrew McGregor
07940 22 33 11

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Same application with different URLs

2009-09-04 Thread Petr Tuma

Hello,

I have a Django application that I need to appear on multiple Apache
virtual hosts with different URLs (e.g. the same view would be
accessible under http://one.site/view and under 
http://another.site/another/path/to/view).
So far, I have tried to have multiple interpreter instances under
mod_python, give each instance a different environment setting via
SetEnv, and branch in urls.py like this:


ServerName "one.site"
SetEnv DJANGO_URL_SITE_ONE ...
...



ServerName "another.site"
SetEnv DJANGO_URL_SITE_TWO ...
...


urls.py:

if "DJANGO_URL_SITE_ONE" in os.environ:
urlpatterns = ... # Patterns for one.site

if "DJANGO_URL_SITE_TWO" in os.environ:
urlpatterns = ... # Patterns for another.site

The approach seems to work somewhat (both sites are visible on the
appropriate URLs), but after doing this, the application itself became
strangely unreliable. When both sites are used, an Error 500: Internal
server error is frequently returned (but mere repeated reloading of
the same page eventually gives a correct page).

Before I go off on hunting the bug somewhere in the application (which
used to work fine before), my question is: is this approach (that is,
having multiple interpreters running multiple instances of the same
application from the same directories, accessing the same database)
something that should work ?

Thanks, Petr

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---