I have many django installation which must run under one URL only. So I have a structure like
- Django Installation 1
-
Django Installation 2
-
Django Installation N
under my root directory.
Now from the URL “www.mysite.com/installation1” I pick up subpart “installation1” and set the os.environ[‘DJANGO_SETTINGS_MODULE’] to “installation.settings” and let the request be handled. Now for the request “www.mysite.com/installation2” I must do the same. However since django caches site object, AppCache etc internally I must restart wsgi process before each request so that internal cache of django gets cleared. ( I know performance would not be good but Im not worried about that). To implement the above scenerio I have implemented the below solution:
- In httpd.conf as WSGIDaemonProcess django processes=5 threads=1
-
In the django.core.handlers.wsgi I made the following change in def “call“
if environ['mod_wsgi.process_group'] != '': import signal, os print 'Sending the signal to kill the wsgi process' os.kill(os.getpid(), signal.SIGINT) return response
My assumption being that deamon process would be killed at each request after the response has been sent. I want to confirm this assumption that my process would only be killed only and only after my response has been sent.
Also is there another way I can solve this problem
Thanks
EDIT: After the suggestion to set the MaxRequestsPerChild to 1 I made the following changes to httpd.conf
KeepAlive Off
Listen 12021
MaxSpareThreads 1
MinSpareThreads 1
MaxRequestsPerChild 1
ServerLimit 1
SetEnvIf X-Forwarded-SSL on HTTPS=1
ThreadsPerChild 1
WSGIDaemonProcess django processes=5 threads=1
But my process is not getting restarted at each request. once the process is started it keeps on processing the request. Am i missing something?
This should be possible using the apache directive
MaxRequestsForChildto 1 as stated in http://httpd.apache.org/docs/2.2/mod/mpm_common.html#maxrequestsperchildHowever it will be global to every process daemon.
Update:
Or you chould check
maximum-requestsoption into WSGIDaemonProcess as in http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines