PyMongo and mod_wsgi
- Run in daemon mode with the
WSGIDaemonProcess
directive. - Assign each application to a separate daemon with
WSGIProcessGroup
. - Use to ensure your application is runningin the daemon’s main Python interpreter, not a sub interpreter.
For example, this mod_wsgi
configuration ensures an application runs in themain interpreter:
- <VirtualHost *>
- WSGIDaemonProcess my_process
- <Location /my_app>
- WSGIProcessGroup my_process
- </Location>
- WSGIDaemonProcess my_other_process
- <Location /my_other_app>
- WSGIProcessGroup my_other_process
- </Location>
- WSGIApplicationGroup %{GLOBAL}
Background: mod_wsgi
can run in “embedded” mode when only WSGIScriptAliasis set, or “daemon” mode with WSGIDaemonProcess. In daemon mode, can run your application in the Python main interpreter, or in sub interpreters.The correct way to run a PyMongo application is in daemon mode, using the maininterpreter.
Beginning with PyMongo 2.7, the C extension for BSON detects when it is runningin a sub interpreter and activates a workaround, which adds a small cost toBSON decoding. To avoid this cost, use WSGIApplicationGroup %{GLOBAL}
toensure your application runs in the main interpreter.