17

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?

2 Answers 2

37

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.

5
  • 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, 2017 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. Dec 7, 2017 at 10:54
  • The application-group option on WSGIScriptAlias is an alternative to using WSGIApplicationGroup. Dec 7, 2017 at 10:55
  • I had this error come in random (probably because of numpy) and crash my site. I just did what you said and I don't know if it works. Do you have any idea on how I could try to reproduce the error ?
    – Sam
    May 4, 2020 at 10:59
  • Just want to update that this answer worked for me after updating to mod_wsgi 5.0.0 running python 3.10.11. The http error Timeout when reading response headers from daemon process... in both MacOS and Linux. This error occurred when importing my python webapp. Hope this information helps someone. Feb 5 at 19:02
5

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
  • 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. Jun 8, 2015 at 23:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .