PyMongo and mod_wsgi

    • Run in daemon mode with the WSGIDaemonProcess directive.

    • Assign each application to a separate daemon with WSGIProcessGroup.

    For example, this mod_wsgi configuration ensures an application runs in the main interpreter:

    If you have multiple applications that use PyMongo, put each in a separate daemon, still in the global application group:

    1. <VirtualHost *>
    2. WSGIDaemonProcess my_process
    3. WSGIProcessGroup my_process
    4. </Location>
    5. WSGIDaemonProcess my_other_process
    6. <Location /my_other_app>
    7. WSGIProcessGroup my_other_process
    8. WSGIApplicationGroup %{GLOBAL}

    Python C extensions in general have issues running in multiple Python sub interpreters. These difficulties are explained in the documentation for Py_NewInterpreter and in the section of the mod_wsgi documentation.

    Beginning with PyMongo 2.7, the C extension for BSON detects when it is running in a sub interpreter and activates a workaround, which adds a small cost to BSON decoding. To avoid this cost, use WSGIApplicationGroup %{GLOBAL} to ensure your application runs in the main interpreter.