Gevent
PyMongo uses thread and socket functions from the Python standard library. Gevent’s monkey-patching replaces those standard functions so that PyMongo does asynchronous I/O with non-blocking sockets, and schedules operations on greenlets instead of threads.
When shutting down, if your application calls join() on Gevent’s without first terminating these background greenlets, the call to join() blocks indefinitely. You therefore must close or dereference any active before exiting.
import signal
def graceful_reload(signum, traceback):
"""Explicitly close some global MongoClient object."""
signal.signal(signal.SIGHUP, graceful_reload)
Applications using uWSGI prior to 1.9.16 are affected by this issue, or newer uWSGI versions with the option. See the uWSGI changelog for details.