问题
Given a simple apache2 conf as below, when will django.wsgi execute? It seems like it executes only the first time a query arrives and never again. I was expecting it to execute on apache startup and then never again. Can anybody shed some light on how this works?
WSGIDaemonProcess site-1 user=user-1 group=user-1 threads=25
WSGIProcessGroup site-1
WSGIScriptAlias / /usr/local/django/mysite/apache/django.wsgi
<Directory /usr/local/django/mysite/apache>
Order deny,allow
Allow from all
</Directory>
回答1:
WSGI script files are technically not executed but are imported. Thus they are like any other module in Python, they are loaded once. In this case it occurs when the request first arrives and the application mapped by that WSGI script file is required.
Once loaded, the WSGI application object is executed once per request.
There are some exceptions to that as far as reloading of the WSGI script file in certain circumstances. For an explanation of that read:
- http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode
Now although it is loaded the first a request requires it to be, you can force that it be loaded on process startup using the WSGIImportScript directive:
- http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIImportScript
or the use of process-group and application-group options together with the WSGIScriptAlias directive. The latter was introduced in mod_wsgi 3.o.
- http://code.google.com/p/modwsgi/wiki/ChangesInVersion0300
来源:https://stackoverflow.com/questions/16746269/when-does-apache2-execute-a-wsgi-script-when-using-daemon-process-groups