doc:http://kazoo.readthedocs.org/en/latest/basic_usage.html

eg:
from kazoo.client import KazooClient

zk = KazooClient()
zk.start()
#!/bin/env python

#Zookeeper test
#Date 2013-03-11 import sys
sys.path.append('/global/exec/weizhong/lib')
import time
from kazoo.client import KazooClient #init the client connect tb055 zookeeper server
zk = KazooClient('tb055:2181',10.0)
zk.start() #lock =zk.Lock('/weidata') #get the list
children = zk.get_children('/')
print children
#exec ruok command
ruok = zk.command('ruok')
print ruok
#get the version of the zookeeper server
version = zk.server_version()
print version
#create
if not zk.exists('/weizhong'):
zk.create('/weizhong',b'Welcome to the servr on tb055')
print zk.exists('/weizhong1')
data,state = zk.get('/weizhong') print data
print state #stop the session
#zk.stop()
#watcher test
#当改变时调用
@zk.ChildrenWatch("/")
def watch_children(children):
print("Children are now: %s" % children)
time.sleep(5)
# Above function called immediately, and from then on @zk.DataWatch("/weidata")
def watch_node(data, stat):
print("Version: %s, data: %s" % (stat.version, data.decode("utf-8"))) def my_func(event):
#check to see what the children are now
print 30*'-' # Call my_func when the children change
children = zk.get_children("/", watch=my_func)
zk.stop()

Python connect zookeeper use the kazoo module的更多相关文章

  1. 使用python操作zookeeper

    kazoo 介绍 zookeeper的开发接口以前主要以java和c为主,随着python项目越来越多的使用zookeeper作为分布式集群实现,python的zookeeper接口也出现了很多,现在 ...

  2. Python 基于Python及zookeeper实现简单分布式任务调度系统设计思路及核心代码实现

    基于Python及zookeeper实现简单分布式任务调度系统设计思路及核心代码实现   by:授客 QQ:1033553122 测试环境 功能需求 实现思路 代码实践(关键技术点实现) 代码模块组织 ...

  3. python 访问 zookeeper

    python 访问 zookeeper zookeeper 分布式服务框架是 Apache Hadoop 的一个子项目,它主要是用来解决分布式应用中经常遇到的一些数据管理问题,如:统一命名服务.状态同 ...

  4. Python 基于python操纵zookeeper介绍

    基于python操纵zookeeper介绍 by:授客  QQ:1033553122 测试环境 Win7 64位 Python 3.3.4 kazoo-2.6.1-py2.py3-none-any.w ...

  5. python连接zookeeper的日志问题

    用python连接zookeeper时,在终端里,一直会有zookeeper的日志冒出来,这样会很烦. -- ::,:(: Exceeded deadline by 11ms 解决方法是在连接后设置一 ...

  6. python中根据字符串导入模块module

    python中根据字符串导入模块module 需要导入importlib,使用其中的import_module方法 import importlib modname = 'datetime' date ...

  7. Python提示AttributeError 或者DeprecationWarning: This module was deprecated解决方法

    Python提示AttributeError 或者DeprecationWarning: This module was deprecated解决方法 在使用Python的sklearn库时,发现sk ...

  8. [转]Python中出错:ImportError: No module named win32com.client

    Python中出错:ImportError: No module named win32com.client [问题] [已解决]Python中处理操作Excel中的图表(Chart,Graph) 的 ...

  9. [py]python操作zookeeper

    参考: https://blog.csdn.net/heizistudio/article/details/79568188 1.安装zookeeper zookeeper-3.4.6.tar.gz ...

随机推荐

  1. (转)Java Ant build.xml详解

    1,什么是ant ant是构建工具2,什么是构建概念到处可查到,形象来说,你要把代码从某个地方拿来,编译,再拷贝到某个地方去等等操作,当然不仅与此,但是主要用来干这个3,ant的好处跨平台   --因 ...

  2. mysql select 语法

    格式:select [选项子句] 字段表达式子句 [from子句] [where子句] [group by子句] [having子句] [order by子句] [limit子句]; 提示:子句的顺序 ...

  3. 高效删除 ListItem

    The most efficient way to a lot of transaction in SharePoint is using of SPWeb.ProcessBatchData meth ...

  4. WebStrom安装了angularjs插件,但是没有语法提示

    你必须要将angular.js文件放在当前工程下才能激活代码提示功能.

  5. setTimeout 和 setInterval区别

    setTimeout和setIntelval都有定时的功能!!!取消定时功能的时候,都有对应的clearTimeout以及clearInterval与之对应. 但是他们之间是有区别的! setTime ...

  6. Linq转成sql后的分页方法

    sql 分页 -- Region Parametersdeclare @pageindex int set @pageindex=2set @pagesize=10 DECLARE @p0 Int = ...

  7. jQuery无刷新上传学习心得

    记得刚离开大学,进入目前这家公司不到一个月时,有一位前辈给我们当时的新人讲了下JS无刷新上传的相关知识. 在此之前,一直都是在使用C#提供的服务器上传控件FileUpload,但是每次使用时,都会刷新 ...

  8. 学习protobuf

    一.认识Protobuf ref:http://blog.csdn.net/program_think/article/details/4229773摘要:1. protobuf是一个开源项目.2. ...

  9. gray code 格雷码 递归

    格雷码 the n-1 bit code, with 0 prepended to each word, followd by the n-1 bit code in reverse order, w ...

  10. Spring MVC 3.2 406 Not Acceptable

    Spring MVC 3.2 406 Not Acceptable 这个报错主要是因为SpringMVC配置文件配置问题. 修改步骤如下: 首先,修改spring-mvc.xsd为 spring-mv ...