You can use threading.Lock
to implement this requirement; it blocks the program until there is a child node of /distribute-lock delete or add.
Code:
#!/usr/bin/env python3
from kazoo.client import KazooClient
from threading import Lock
zkl = Lock()
def my_func(event):
if event.type == 'CHILD':
zkl.release()
zk = KazooClient(hosts='127.0.0.1:2181')
zk.start()
zkl.acquire()
children = zk.get_children("/distribute-lock", watch=my_func)
zkl.acquire()
zk.stop()