When does apache2 execute a .wsgi script when using daemon process groups?

浪子不回头ぞ 提交于 2019-12-12 01:12:51

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!