2

How to explicitly stop datawatch process started on a zNode using python module kazoo? Below is the way I created datawatch

from   kazoo.recipe.watchers    import DataWatch
datawatch = DataWatch(client=zookeeper_client, path=path_to_znode, func=callback_function)

I went through kazoo wiki and figured out below ways.

  1. Returning False from callback method passed(here callback_function) will stop datawatch on the zNode. But this way is not suitable for me as callback_function is handled by users and not in my hand.
  2. When process stops datawatch automatically gets killed. But I don't want to stop the process.
  3. This is the hacky way I am using currently. There is a private member variable "_stopped" under datawatch class. I am setting it to true.

    datawatch._stopped = True
    

Can someone please suggest better solution here. Thanks.

Akshay
  • 1,231
  • 1
  • 19
  • 31

1 Answers1

1

The DataWatch Doc also says:

If the client connection is closed (using the close command), the DataWatch will no longer get updates. So stopping the zookeeper client should be enough.

from kazoo.client import KazooClient

zk = KazooClient(hosts='127.0.0.1:2181')
zk.start()
datawatch = DataWatch(client=zk, path=path_to_znode, func=callback_function)
# time pass....
zk.stop()
Lorenzo Belli
  • 1,767
  • 4
  • 25
  • 46
  • Thanks @Lorenzo, But I already mentioned in point 2 of my question that my case do not allow me to close the client connection. – Akshay Feb 07 '17 at 04:20