Why does mod_wsgi handle request in non-main thread when WSGIScriptAlias has both application-group and process-group

Viewed 59

I am using apache(2.4.6) with mod_wsgi(4.6.5) in daemon mode. I am currently working on a project which needs to preload the WSGI application.

This is the configuration i was using before:

<VirtualHost *:8080>
  DocumentRoot /path/to/repro/wwwroot
  WSGIDaemonProcess repro processes=1 threads=1 display-name=repro maximum-requests=0 
  WSGIProcessGroup repro
  WSGIScriptAlias /repro /path/to/repro.py process-group=repro    
  WSGIApplicationGroup %{GLOBAL}
</VirtualHost>

This is the repro.py file:

import os
import web
import sys
import threading

urls = (
   '/', 'index'
)

class index:
    def GET(self):
        print(threading.main_thread())
        print(threading.current_thread())
        print(threading.enumerate())
        return "Hello, world!"

application = web.application(urls, globals()).wsgifunc()

According to the following two resources:

I changed the configuration to this:

<VirtualHost *:8080>
  DocumentRoot /path/to/repro/wwwroot
  WSGIDaemonProcess repro processes=1 threads=1 display-name=repro maximum-requests=0
  WSGIScriptAlias /repro /path/to/repro.py process-group=repro application-group=%{GLOBAL}
  WSGIProcessGroup repro
  WSGIApplicationGroup %{GLOBAL}
</VirtualHost>

i.e specified both application-group and process-group directive. This solved the pre-loading problem for us.

But, the difference here is that in the first case all the requests were being handled by the main thread but after the configuration change, the requests are now being handled in the non-main thread. We have a bunch of code that requires things to be run on the main thread and were running previously but after the change, it is causing them to fail.

Any solution for this?

Thank you

0 Answers
Related