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

我的未来我决定 提交于 2019-12-03 00:46:24

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.

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!