mod wsgi – the mod_wsgi processes die prematurely in the Django application

I'm having a strange problem with mod_wsgi and Django in my local development environment, which is a Macbook Pro that runs macOS 10.13.6. In the past, I used to use Bitnami MAMP stacks for my Apache and MySQL instances (I also do some PHP development), with Python installed through Homebrew and running on virtualenvs. The operating system updates always invited a lot of dynamically loaded library conflicts, and with the update to 10.13 I finally had enough and decided to get rid of Bitnami stacks and simply rely on Homebrew for everything from now on. I installed Apache and MySQL without any problem and I configured my configuration basically as it was before. I have to run my Django applications, but they were surprisingly slow. While typical latencies in the past were around 200 ms or less, I now saw 1-2 seconds of latency in each request.

After some experiments, I discovered that each request went to a new WSGI process. This is despite the fact that I am running mod_wsgi in daemon mode with the same WSGI configuration that I used to do. To solve more problems, I created a new virtualenv with a new Django installation that contains a single page that prints the process ID that represented it. The problem persisted here. Then I modified my WSGI file to simply print the pid without calling the Django WSGI application. The interesting thing that I discovered here is that even if I do not call the Django WSGI application, the loss of processes occurs as long as the import of get_wsgi_application since django.core.wsgi If I comment on that import, after a couple of requests, the pid is stabilized and all subsequent requests are handled by the same process.

I am running Apache 2.4.37 using the MPM event (although the choice of MPM does not seem to affect anything in relation to this problem). I am using Python 3.6.5 with mod_wsgi 4.6.5 installed through pip. Here is my VirtualHost configuration:

WSGIDaemonProcess wsgitest display-name =% {GROUP} python-path = / path / to / app python-home = / path / to / venv
WSGIProcessGroup wsgitest
WSGIScriptAlias ​​/ /path/to/app/

        Require all granted

Here is my WSGI file:

OS import

from django.core.wsgi import get_wsgi_application

os.environ.setdefault (& # 39; DJANGO_SETTINGS_MODULE & # 39 ;, & # 39; wsgitest.settings & # 39;)

def application (environ, start_response):
body = & # 39; Running in the process {} & # 39 ;. format (os.getpid ()). encode (& # 39; utf-8 & # 39;)
status = & # 39; 200 OK & # 39;
response_headers = [
        ('Content-Type', 'text/plain'),
        ('Content-Length', str(len(body)))
    start_response (state, response_headers)
he came back [body]

With the above, in each request, the process ID changes. If I comment the import of get_wsgi_application, this does not happen What's happening?