kazoo icon indicating copy to clipboard operation
kazoo copied to clipboard

SequentialGeventHandler with DataWatch and ChildrenWatch

Open arpanshah29 opened this issue 9 years ago • 0 comments

In my main thread I try to set up a DataWatch and a ChildrenWatch as follows. I have not put all the args since this is just to demonstrate the issue:

seq.py

class Test(object):
    def __init__(self, hosts):
        self.hosts = hosts
        self.foo_count = 0
       self.bar_count = 0
        self.zkclient = KazooClient(hosts=self.hosts,
                                         handler=SequentialGeventHandler())
       self.zkclient.ChildrenWatch("/foo", self.foo_func)
       self.zkclient.DataWatch("/foo/bar",  self.bar_func)

   def foo_func(self):
        self.foo_count += 1

   def bar_func():
       self.bar_count += 1

Within zookeeper I have a node "/foo/bar"

I then have a script that just instantiates the Test object and does the following in a loop

test.py:

from seq import Test
from time import sleep

test = Test("localhost:2181")
while True:
     test.sleep(5)
     print test.foo_count
     print test.bar_count

When I run test.py and change the values of /foo/bar, I don't see the value of foo_count and bar_count incrementing. I.e both counts remain 1 no matter how many times I change "/foo/bar" or add children to "/foo".

It works as expected when I run it with the Threaded handler. I am unsure why and would appreciate help in figuring out why that is the case. Also it would be great to see a working example of the SequentialGeventHandler with the watch recipes. Thanks and apologies in advance if this is not the right forum for concerns like this one

arpanshah29 avatar Aug 04 '16 22:08 arpanshah29