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:

    1. <VirtualHost *>
    2. WSGIDaemonProcess my_process
    3. <Location /my_app>
    4. WSGIProcessGroup my_process
    5. </Location>
    6.  
    7. WSGIDaemonProcess my_other_process
    8. <Location /my_other_app>
    9. WSGIProcessGroup my_other_process
    10. </Location>
    11.  
    12. 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.