Very nice. I have moved import inside the application call but was concerned about evaluating that impot on every request. Looks like you got that covered.
-- With you setup is it possible to run into some race conditions when two simultaneous request coming for the first time when _application is still uninitialized?
On Thursday, November 21, 2013 11:31:15 AM UTC-8, Jon Dufresne wrote:
On Thursday, November 21, 2013 11:31:15 AM UTC-8, Jon Dufresne wrote:
On Thu, Nov 21, 2013 at 8:46 AM, Mike Starov <mikes...@gmail.com> wrote:
> I encountered same issue in my deployment. Have you found a solution?
>
Yes I did. I am still not sure if this is a bug or intentional. It
appears that in 1.6, settings.py is now imported *before* the first
run of the WSGI application. Therefore the settings.py is loaded
before the environment variables can be setup. I now load the WSGI
application as late as possible using the following code. This way,
the settings.py isn't imported until I've received the environ from
Apache. Please feel free to use it to fix your project:
---
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
_application = None
def application(environ, start_response):
os.environ['MY_SETTING'] = environ['MY_SETTING']
global _application
if _application is None:
from django.core.wsgi import get_wsgi_application
_application = get_wsgi_application()
return _application(environ, start_response)
---
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/83657958-07f5-4dcf-865b-812b54637ef5%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment