kazoo icon indicating copy to clipboard operation
kazoo copied to clipboard

ConnectionLoss when using SequentialGeventHandler in interactive way

Open wangxiangyu opened this issue 10 years ago • 3 comments

hi, all I am try to use kazoo with SequentialGeventHandler in an interactive way(ipython). Here is the command:


In [1]: from kazoo.client import KazooClient
In [2]: from kazoo.handlers.gevent import SequentialGeventHandler
In [3]: zk= KazooClient(hosts='192.168.2.5:2181',handler=SequentialGeventHandler())
In [4]: zk.start()
But after a few seconds, the connection between the client and zk server is closed. So Datawatch never works correctly. If I use SequentialThreadingHandler and also in the interactive mode , It works well. I think it is related to the interactive mode I use, because if I put the code in the file, then run it,it works ok. like:

from kazoo.client import KazooClient
from kazoo.handlers.gevent import SequentialGeventHandler
import gevent
zk= KazooClient(hosts='192.168.2.5:2181',handler=SequentialGeventHandler())
zk.start()
while True:
    gevent.sleep(1)

I don't know the deep reason of it. Any ideas? Thank you!

wangxiangyu avatar Mar 02 '15 07:03 wangxiangyu

Afaik gevent (and eventlet) only switch to other threads when a blocking operation occurs. If none occurs in your interactive python then I would expect it to timeout (which is also the reason your loop does work, since it is forcing greenthreads to be switched into). Since the threading handler uses native threads that works correctly, I wouldn't recommend using gevent or eventlet handlers in such interactive modes (due to mentioned issues).

harlowja avatar Mar 03 '15 23:03 harlowja

@harlowja Thanks for your reply. The issus you mentioned is exactly the deep reason. Why I want to use ipython is because it is convenient to debug. Althougth I use SequentialThreadingHandler , if the code which imports kazoo contains "gevent.monkey.patch_all()", the problem still exists.

wangxiangyu avatar Mar 04 '15 02:03 wangxiangyu

That's probably because monkey patch all patches threading code; which then results in the same issue right? This same thing will happen with eventlet to (which has a similar monkey patch routine).

harlowja avatar Mar 04 '15 05:03 harlowja