Solution
_mongo_client = None
_mongo_client_pid = None
def get_mongoclient():
global _mongo_client, _mongo_client_pid
if os.getpid() != _mongo_client_pid:
_mongo_client = MongoClient(...)
_mongo_client_pid = os.getpid()
return _mongo_client
try:
from uwsgi import postfork
except ImportError:
postfork = lambda f: f # no-op decorator