Hello,
in my application I use the gevent event loop in a separate thread for a dedicated and optimized task. To run the gevent event loop in a another thread than the main thread, means to import gevent lazily.
The other parts of my application use the old threaded/synchronous approach. Unfortunately in the threaded/sync parts of the code I'm using pymongo as well. However with newer versions of pymongo gevent is imported at module initialization time of pymongo. But this makes the lazy import in my other thread failing.
Here is a simplified example how to trigger the error. I executed with the following versions
* cpython2.7
* pymongo == 2.3
* gevent == 0.13.8
i
mport pymongoimport threadingdef error(): import gevent gevent.sleep(1)t = threading.Thread(target=error)t.start()t.join()To make it running I have to
* import pymongo lazily everywhere
* ensure that the thread, running the gevent event loop, runs first to do the 'gevent import'
Or
* running the gevent-event-loop in the main thread
Both options are pretty hard to implement on my side, so I'm kindly asking if pymongo can defer the import of 'gevent' until it really uses its features ?
If this change is accepted, I can write a patch of my own and send a pull request here
https://github.com/mongodb/mongo-python-driverImportant note to avoid confusion: I'm *not* using pymongo in the thread running gevent. So I do *not* need support for pymongo running with threads and gevent at the same time. In need pymongo in the threaded environment, just without the gevent import hassle