Timeout with Flask/uWSGI/nginx app using mongodb Timeout with Flask/uWSGI/nginx app using mongodb nginx nginx

Timeout with Flask/uWSGI/nginx app using mongodb


I believe the issue is that you're forking and this causes issues with PyMongo.

PyMongo is thread safe but not Fork safe. Once you run the app in daemon mode you are forking the process. You'll have to create a MongoClient inside the app so that your threads can see it after the process has started.

You can try this(I didn't try this out, I normally wrap stuff like this in a class and do this in the init method):

def create_app(app_name='MYAPP'):   app.client = pymongo.MongoClient(connect=False) # this will prevent connecting until you need it.   app.db = app.client.myapp   return app

Read this: http://api.mongodb.com/python/current/faq.html#id3