-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathzoo.py
More file actions
34 lines (25 loc) · 779 Bytes
/
zoo.py
File metadata and controls
34 lines (25 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from kazoo.client import KazooClient
from kazoo.exceptions import NoNodeError
from kazoo.exceptions import NodeExistsError
_callback = None
_zk = None
def init_kazoo(hosts, data_path, callback, children=True):
global _zk
global _callback
_zk = KazooClient(hosts=hosts)
_zk.start()
_callback = callback
if data_path:
if children:
@_zk.ChildrenWatch(data_path)
def watch_children(children):
print("Watch Children")
if _callback:
_callback(children)
else:
@_zk.DataWatch(data_path)
def watch_node(data, stat):
print("Watch Node")
if _callback:
_callback(data, stat)
return _zk