5

I want to add watch on all children nodes of a node in Python using kazoo client but ChildrenWatch only watches for child add or remove not for data update of any child node. I am searching for a simple recipe which does this task.

Sample code will be like this

from kazoo.client import KazooClient

zk = KazooClient(hosts='127.0.0.1:2181')
zk.start()

@zk.SomeRecipe("/root")
def watch_children_update(event):
    print("Updated child at path:%s data:%s stat:%s" % event.path, event.data, event.stat)
Lorenzo Belli
  • 1,767
  • 4
  • 25
  • 46
Black_Rider
  • 1,465
  • 2
  • 16
  • 18

2 Answers2

0
from kazoo.client import KazooClient

@client.DataWatch('/path/to/watch')
def my_func(data, stat):
    print("Data is %s" % data)
    print("Version is %s" % stat.version)

# Or if you want the event object
@client.DataWatch('/path/to/watch')
def my_func(data, stat, event):
    print("Data is %s" % data)
    print("Version is %s" % stat.version)
    print("Event is %s" % event)

What do you need is a DataWatch

Lorenzo Belli
  • 1,767
  • 4
  • 25
  • 46
0

The children under a node have changed (a child was added or removed). This event does not indicate the data for a child node has changed, which must have its own watch established.

kook
  • 180
  • 1
  • 6