Received: by 10.224.219.144 with SMTP id hu16mr2455982qab.1.1353047467300; Thu, 15 Nov 2012 22:31:07 -0800 (PST) X-BeenThere: mongodb-user@googlegroups.com Received: by 10.49.131.41 with SMTP id oj9ls750878qeb.77.gmail; Thu, 15 Nov 2012 22:30:42 -0800 (PST) Received: by 10.49.87.1 with SMTP id t1mr742910qez.41.1353047442387; Thu, 15 Nov 2012 22:30:42 -0800 (PST) Date: Thu, 15 Nov 2012 22:30:41 -0800 (PST) From: Stephan To: mongodb-user@googlegroups.com Message-Id: <85560920-3cae-4f55-996a-d8af951583f4@googlegroups.com> In-Reply-To: <3e7524e1-b2c0-4c00-92dd-360e79b1f36b@googlegroups.com> References: <59e97ce2-b0ac-4d15-9995-2e6f6d9a6eb1@googlegroups.com> <7c3fe0c9-e4fc-483d-90e9-9491e56d8806@googlegroups.com> <3e7524e1-b2c0-4c00-92dd-360e79b1f36b@googlegroups.com> Subject: Re: pymongo and gevent module in different threads MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_2423_2672676.1353047441476" ------=_Part_2423_2672676.1353047441476 Content-Type: multipart/alternative; boundary="----=_Part_2424_23844465.1353047441476" ------=_Part_2424_23844465.1353047441476 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Thanks for the warning. I agree, waiting for the big changes makes the merge easier. Am Donnerstag, 15. November 2012 21:48:23 UTC+1 schrieb A. Jesse Jiryu Davis: > > Be aware that we're about to do a *very* large change, including renaming > the connection.py and replica_set_connection.py files, so you might be > better off waiting until that's done in the next week. Your choice. > > On Thursday, November 15, 2012 3:47:16 PM UTC-5, A. Jesse Jiryu Davis > wrote: >> >> I understand your point. If you'd like to offer a pull request, please do! >> >> On Thursday, November 15, 2012 8:22:51 AM UTC-5, Stephan wrote: >>> >>> 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 >>> >>> >>> import pymongo >>> import threading >>> >>> def 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-driver >>> >>> Important 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 >>> >> ------=_Part_2424_23844465.1353047441476 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable Thanks for the warning. I agree, waiting for the big changes makes the merg= e easier.

Am Donnerstag, 15. November 2012 21:48:23 UTC+1 schrieb A.= Jesse Jiryu Davis:
Be aware th= at we're about to do a very large change, including renaming th= e connection.py and replica_set_connection.py files, so you might be better= off waiting until that's done in the next week. Your choice.

On Thu= rsday, November 15, 2012 3:47:16 PM UTC-5, A. Jesse Jiryu Davis wrote:I understand your point. If you'd like t= o offer a pull request, please do!

On Thursday, November 15, 2012 8:= 22:51 AM UTC-5, Stephan wrote:
Hello= ,

in my application I use the gevent event loop in a separate threa= d for a dedicated and optimized task. To run the gevent event loop in a ano= ther thread than the main thread, means to import gevent lazily.
The oth= er parts of my application use the old threaded/synchronous approach. Unfor= tunately in the threaded/sync parts of the code I'm using pymongo as well.&= nbsp; However with newer versions of pymongo gevent is imported at module i= nitialization time of pymongo. But this makes the lazy import in my other t= hread failing.


Here is a simplified example how to trigger the = error. I executed with the following versions
* cpython2.7
* pymongo = =3D=3D 2.3
* gevent =3D=3D 0.13.8


import pymongo
import t= hreading

def error():
    imp= ort gevent
    gevent.sleep(1)<= /span>

t.sta= rt()
t.join()


To make it running I have to
* import pym= ongo lazily everywhere
* ensure that the thread, running the gevent even= t loop, runs first to do the 'gevent import'
Or
* running the gevent-= event-loop in the main thread

Both options are pretty hard to implem= ent on my side, so I'm kindly asking if pymongo can defer the import of 'ge= vent' 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.c= om/mongodb/mongo-python-driver

Important note to avoid conf= usion: 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
------=_Part_2424_23844465.1353047441476-- ------=_Part_2423_2672676.1353047441476--