pymongo + gevent: throw me a banana and just monkey_patch?

后端 未结 2 447
终归单人心
终归单人心 2021-02-02 17:20

Quickie here that needs more domain expertise on pymongo than I have right now:

Are the \"right\" parts of the pymongo driver written in python for me to call gevent mo

相关标签:
2条回答
  • 2021-02-02 17:49

    On initial inspection it doesn't appear to do any socket operations in the c code so it should be fine (blocking ops should just block the green thread).

    0 讨论(0)
  • 2021-02-02 18:02

    I have used PyMongo with Gevent and here are a few things you need to watch out for:

    1. Instantiate only one pymongo.Connection object, preferrably as a global or module-level variable. This is important because Connection has within itself a pool!
    2. Monkey patch everything, or at least BOTH socket and threading. Due to the use of thread locals in Connection, patching socket alone is not enough.
    3. Remember to call end_request to return the connection to the pool.

    The answer to your question is go ahead, PyMongo works just fine with Gevent.

    0 讨论(0)
提交回复
热议问题