I am using Celery and MongoEngine as part of my Django App with.
I am getting this warning, when a celery @shared_task accesses the mongodb database via mongoengine model classes:
UserWarning: MongoClient opened before fork. Create MongoClient with
connect=False,or create client after forking. See PyMongo's
documentation for details:
http://api.mongodb.org/python/current/faq.html#using-pymongo-with-multiprocessing
It clearly has something to do with multiprocessing and pyMongo that is that mongoengine is based on.
My question is:
What is the best strategy to avoid this issue with mongoengine?
Please note that i am connecting to the mongodb with mongoengine in the settings.py
:
mongoengine.connect('my_mongo_database_name', alias='default')
After searching a little bit online, i found out that it is possible to pass additional arguments to the mongoengine.connect
function the additional arguments will be passed to the underlying PyMongo
classes & functions.
So i simply edited the mongoengine.connect()
call to the following:
mongoengine.connect('my_mongo_database_name', alias='default', connect=False)
And the warning stopped appearing. None the less i am not sure this is the best way to deal with the warning. If you have a better answer please post it and i will gladly test it and eventually accept it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With