10

I am currently running a Centos 6.4 server, with Apache 2.2.15 and mod_wsgi 3.2. The server is hosting a django-based site (django 1.5.1, python 2.6.6). Everything was running fine until I installed scipy 0.12.0 via pip. Now, when I attempt to load the django app, the server does not respond, and it appears that child httpd processes that are spawned hang. Looking through my logs (/var/logs/httpd/error_log, my vhost error.log, and my system logs) yield no errors.

If I load my models, etc.. via the django manage.py shell, everything works fine, which leads me to believe it is a mod_wsgi issue.

Any thoughts on how to start troubleshooting this?

18

Some third party packages for Python which use C extension modules, and this includes scipy and numpy, will only work in the Python main interpreter and cannot be used in sub interpreters as mod_wsgi by default uses. The result can be thread deadlock, incorrect behaviour or processes crashes. These is detailed in:

http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Python_Simplified_GIL_State_API

The workaround is to force the WSGI application to run in the main interpreter of the process using:

WSGIApplicationGroup %{GLOBAL}

If running multiple WSGI applications on same server, you would want to start investigating using daemon mode because some frameworks don't allow multiple instances to run in same interpreter. This is the case with Django. Thus use daemon mode so each is in its own process and force each to run in main interpreter of their respective daemon mode process groups.

  • Hi Graham, could you update this answer in the context of more recent versions of mod-wsgi? Specifically, is this supposed to be a problem by default if I have configured apache using mod_wsgi-express? In the generated httpd.conf file, WSGIApplicationGroup is not used. However, there is application-group=${GLOBAL} in the <IfDefine ONE_PROCESS> and <IfDefine !ONE_PROCESS> blocks. I see a WSGIDaemonProcess directive in the generated httpd.conf file. Does that mean it's already using daemon mode by default? – Kal Dec 7 '17 at 9:12
  • If you use mod_wsgi-express start-server or Django integration for mod_wsgi-express it runs with daemon mode as default and use the main interpreter. So this is not a problem in that case. If you manually configure Apache, then is still an issue. The ONE_PROCESS part is only for when you force it into debug mode, in which case it runs in single process embedded mode. It still runs in main interpreter though. – Graham Dumpleton Dec 7 '17 at 10:54
  • The application-group option on WSGIScriptAlias is an alternative to using WSGIApplicationGroup. – Graham Dumpleton Dec 7 '17 at 10:55
2

Another solution that fit my way of configuring WSGI was changing the WSGIScriptAlias line:

WSGIDaemonProcess website user=user group=group python-path=/path/to/venv/website:/path/to/venv/lib/python2.7/site-packages
WSGIScriptAlias /website /path/to/venv/website/wsgi.py process-group=website application-group=%{GLOBAL}

<Location /website>
        WSGIProcessGroup website
</Location>

<Directory /path/to/venv/website>
        WSGIScriptReloading On
        <Files wsgi.py>
                Allow from all
                Require all granted
        </Files>
</Directory>

note the attributes

process-group=website application-group=%{GLOBAL}

which are usually not required

  • 1
    You can drop WSGIScriptReloading directive as that defaults to on and generally would never need to be turned off. Due to using process-group option to WSGIScriptAlias, you can also drop the WSGIProcessGroup directive. – Graham Dumpleton Jun 8 '15 at 23:56

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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