M
M
Max Payne2019-02-14 20:48:35
Python
Max Payne, 2019-02-14 20:48:35

How to use mongoengine.connect when multiprocessing?

I have a module in my project that contains document models. At the end of the file there is a line from the official mongoengine documentation.
connect(DB_HOST)
Further, all calls to this module occur inside tornado processes, for example

from core import models
...
owners = models.Owner.objects()
...

However, during the execution of the program, mongoengine displays warnings that you should not do this, because models is open before the threads start (as far as I understand, the connection was established before the threads started?)
UserWarning: MongoClient opened before fork. Create MongoClient only after forking. See PyMongo's documentation for details: api.mongodb.org/python/current/faq.html#is-pymongo...
"MongoClient opened before fork. Create MongoClient only "

How can I correctly use connect?
UPD. I tried in each file where I use models to establish a separate connection (call connect()), but this did not solve the problem.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2019-02-14
@YardalGedal

As far as I know, mongoengine is bad for working with asynchronous frameworks, since calls through it are blocking. Better use a motor

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question