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:


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

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

# Add the app's directory to the PYTHONPATH

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

# Activate your virtual env
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?


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.