Non-responsive apache + mod_wsgi after installing scipy
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?
Solution 1:
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.
Solution 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