3

I'm relatively new to all the server technology and I followed this tutorial to deploy my django app on an Apache Webserver, using mod_wsgi:

http://thecodeship.com/deployment/deploy-django-apache-virtualenv-and-mod_wsgi/

Here is my virtual hosts file:

<VirtualHost *:80>
        ServerName www.abcxyz.org
        ServerAlias abcxyz.org
        WSGIScriptAlias / /var/www/abcxyz/django/abcxyz/wsgi_prod.py
        Alias /static/ /var/www/abcxyz/static/
        <Location "/static/">
            Options -Indexes
        </Location>
</VirtualHost>

As I understand it, the wsgi_prod.py file should only be executed once when the server starts (or when it gets the first request - I'm not particular sure about this). But in my application it is executed multiple times, when sending requests to the server.

It is not executed on all requests but on some of them. And there are also some request, that trigger the execution of wsgi_prod.py only sometimes.

This is my wsgi_prod.py file:

import os
import sys
import site
import thread


# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('/etc/Envs/abcxyz/local/lib/python2.7/site-packages')

# Add the app's directory to the PYTHONPATH
sys.path.append('/var/www/abcxyz/django')
sys.path.append('/var/www/abcxyz/django/abcxyz')


os.environ['DJANGO_SETTINGS_MODULE'] = 'abcxyz.settings.production'

# Activate your virtual env
activate_env=os.path.expanduser("/etc/Envs/abcxyz/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))


print "WSGI RUN!!!"

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Has anyone any idea what could have went wrong in my case and where I could start searching for the error?

4

It would be loaded once per process.

You likely are using a multiprocess configuration and subsequent requests are being handled by different process and/or processes are being recycled. Print out the process ID in the debug. Also go read:

and watch:

  • Awesome, I followed the instructions of your second link and it work properly now. Thanks a lot! – basilikum Dec 20 '13 at 9:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.