What exactly is wrong with using pymongo in twisted?

I have a twisted server application that maintains persistent connections with about 1000 clients. Each client will sometimes send data to my twisted server, and I would like this server to store data in a MongoDB database. So far so good.

But the pymongo documentation states something like "there is no good way to use pymongo with twisted". I don’t understand why not. Can someone please explain what exactly is the problem and what are the pitfalls? I think it has to do with the fact that pymongo is synchronous, but all I want to do is throw some things into the database.

If I have one pymongo.MongoClient instance declared in connector.py and then I import the connector into the main python file that runs my Twisted factory and protocols, I should be able to use that pymongo.MongoClient instance in each protocol (connection with each client) to store the data in the database.

So what's the problem? Obviously I'm a little confused.

+3


source to share


1 answer


In short : calls to pymongo block when they run, they freeze the twisted engine until the call returns, which is randomly destructive to the twisted internal state because it is the opposite of what is meant to be twisted.

Instead, you should look for a twisted comparable driver like tx-mongo . tx-mongo has a smaller audience than pymongo and therefore its documentation is a bit roughly comparable, but you should find everything you need in it example

.



Background: Threading vs Event programing

+5


source







All Articles