I'm trying to operate a Python application within Apache (prefork) with WSGI in a way that the single Python interpreter is going to be used. This really is necessary because the application uses thread synchronization to avoid race conditions from occurring. Since Apache prefork spawns multiple processes, the code ends up not shared between your interpreters and therefore the thread synchronization does not matter (i.e. each thread only sees it own locks without any effect on another processes).
This is actually the setup:
- Apache 2. (prefork)
- Python 2.5
This is actually the relevant Apache configuration:
WSGIApplicationGroup % <VirtualHost _default_:80> WSGIScriptAlias / /var/convergedsecurity/apache/osvm.wsgi Alias /admin_media/ /var/world wide web/html/admin_media/ <Directory /var/world wide web/html/admin_media> Order deny,allow Allow all </Directory> Alias /media/ /var/world wide web/html/media/ <Directory /var/world wide web/html/media> Order deny,allow Allow all </Directory> </VirtualHost>
Here's what I attempted to date (none which labored):
- Adding WSGIApplicationGroup %
Indicating WSGIDaemonProcess and WSGIProcessGroup inside the virtual host:
WSGIDaemonProcess osvm threads=50
Can there be not a way to pressure Apache prefork to utilize a single Python interpreter with WSGI? The documents appear to imply you are able to using the WSGIDaemonProcess and WSGIApplicationGroup options but Apache still produces another Python interpreter for every process.
You cannot possess the WSGI application run in embedded mode on UNIX systems, may it be prefork or worker MPM, because there will indeed be multiple processes. See:
Developing a daemon process group composed of single process and assigning WSGI application to that particular should achieve what you would like. You should not even want to use WSGIApplicationGroup if it's just one mounted WSGI application you're speaking about. If you wish to be certain though, you may also place it.
Thus configuration within VirtualHost could be:
WSGIDaemonProcess osvm WSGIProcessGroup osvm WSGIApplicationGroup % WSGIScriptAlias / /var/convergedsecurity/apache/osvm.wsgi
Although 'processes=1' for WSGIDaemonProcess causes it to be explicit that certain process is produced, don't supply the option though and merely allow it to default to 1 process. Any utilization of 'processes' option, even when for just one process might find 'wsgi.multiprocess' set to True.
Instead of make use of your actual WSGI application, I recommend you test using the following simple test program.
import cStringIO import os def application(environ, start_response): headers =  headers.append(('Content-Type', 'text/plain')) write = start_response('200 OK', headers) input = environ['wsgi.input'] output = cStringIO.StringIO() print >> output, "PID: %s" % os.getpid() print >> output secrets = environ.secrets() secrets.sort() for type in secrets: print >> output, '%s: %s' % (key, repr(environ[key])) print >> output output.write(input.read(int(environ.get('CONTENT_LENGTH', '0')))) return [output.getvalue()]
Within the creation of that, the PID value ought to always be exactly the same. The wsgi.multiprocess flag ought to be False. The mod_wsgi.process_group value ought to be no matter what you known as the daemon process group. And also the mod_wsgi.application_group ought to be a clear string.
If the is not what you're seeing, make sure you really restarted Apache after making configuration changes. Include:
to Apache configuration for VirtualHost. Doing which will cause mod_wsgi to log much more messages in Apache error log about process creation and script loading, including particulars of process group and application group situations are happening for.
For additional information on debugging, see:
If still problems, suggest put forth the mod_wsgi subscriber list on the internet Groups.