from kazoo.client import KazooClient
from kazoo.client import KazooState
import time
print time.ctime()
zk = KazooClient(hosts='20.5.101.15:12181',timeout=100)
print zk
print zk.state
zk.start()
print zk.state
print '---------------------------------'
zk.stop()
print zk.state
zk.start()
print zk.state
print zk.state
print zk.state
while True:
time.sleep(1)
print zk.get_children('/')
print zk.get('/scan/001')
[u'aa', u'cluster', u'controller', u'brokers', u'zookeeper', u'scan', u'admin', u'isr_change_notification', u'log_dir_event_notification', u'controller_epoch', u'aaayyy', u'mynode', u'consumers', u'latest_producer_id_block', u'config']
('', ZnodeStat(czxid=8589935253L, mzxid=8589935253L, ctime=1529570656357L, mtime=1529570656357L, version=0, cversion=0, aversion=0, ephemeralOwner=0, dataLength=0, numChildren=0, pzxid=8589935253L))
[u'aa', u'cluster', u'controller', u'brokers', u'zookeeper', u'scan', u'admin', u'isr_change_notification', u'log_dir_event_notification', u'controller_epoch', u'aaayyy', u'mynode', u'consumers', u'latest_producer_id_block', u'config']
('', ZnodeStat(czxid=8589935253L, mzxid=8589935253L, ctime=1529570656357L, mtime=1529570656357L, version=0, cversion=0, aversion=0, ephemeralOwner=0, dataLength=0, numChildren=0, pzxid=8589935253L))
临时节点:
('', ZnodeStat(czxid=8589935253L, mzxid=8589935253L, ctime=1529570656357L, mtime=1529570656357L, version=0, cversion=0, aversion=0, ephemeralOwner=0, dataLength=0, numChildren=0, pzxid=8589935253L))
('', ZnodeStat(czxid=8589935271L, mzxid=8589935271L, ctime=1529570763614L, mtime=1529570763614L, version=0, cversion=0, aversion=0, ephemeralOwner=244355283532578946L, dataLength=0, numChildren=0, pzxid=8589935271L))
[u'aa', u'cluster', u'controller', u'brokers', u'zookeeper', u'scan', u'admin', u'isr_change_notification', u'log_dir_event_notification', u'controller_epoch', u'aaayyy', u'mynode', u'consumers', u'latest_producer_id_block', u'config']
('', ZnodeStat(czxid=8589935253L, mzxid=8589935253L, ctime=1529570656357L, mtime=1529570656357L, version=0, cversion=0, aversion=0, ephemeralOwner=0, dataLength=0, numChildren=0, pzxid=8589935253L))
('', ZnodeStat(czxid=8589935271L, mzxid=8589935271L, ctime=1529570763614L, mtime=1529570763614L, version=0, cversion=0, aversion=0, ephemeralOwner=244355283532578946L, dataLength=0, numChildren=0, pzxid=8589935271L))
[u'001', u'002']
('ceshi 001', ZnodeStat(czxid=8589935302L, mzxid=8589935302L, ctime=1529571007087L, mtime=1529571007087L, version=0, cversion=0, aversion=0, ephemeralOwner=0, dataLength=9, numChildren=0, pzxid=8589935302L))
('ceshi 002', ZnodeStat(czxid=8589935313L, mzxid=8589935313L, ctime=1529571049153L, mtime=1529571049153L, version=0, cversion=0, aversion=0, ephemeralOwner=244355283532578964L, dataLength=9, numChildren=0, pzxid=8589935313L))
('ceshi 002', ZnodeStat(czxid=8589935313L, mzxid=8589935313L, ctime=1529571049153L, mtime=1529571049153L, version=0, cversion=0, aversion=0, ephemeralOwner=244355283532578964L, dataLength=9, numChildren=0, pzxid=8589935313L))
[u'001']
('ceshi 001', ZnodeStat(czxid=8589935302L, mzxid=8589935302L, ctime=1529571007087L, mtime=1529571007087L, version=0, cversion=0, aversion=0, ephemeralOwner=0, dataLength=9, numChildren=0, pzxid=8589935302L))
Traceback (most recent call last):
File "C:/Users/tlcb/PycharmProjects/untitled/rizhiyi/t1.py", line 22, in <module>
print zk.get('/scan/002')
File "C:Python27libsite-packageskazooclient.py", line 1042, in get
return self.get_async(path, watch=watch).get()
File "C:Python27libsite-packageskazoohandlersutils.py", line 79, in get
raise self._exception
kazoo.exceptions.NoNodeError