Python connect zookeeper use the kazoo module
doc:http://kazoo.readthedocs.org/en/latest/basic_usage.html
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的更多相关文章
- 使用python操作zookeeper
kazoo 介绍 zookeeper的开发接口以前主要以java和c为主,随着python项目越来越多的使用zookeeper作为分布式集群实现,python的zookeeper接口也出现了很多,现在 ...
- Python 基于Python及zookeeper实现简单分布式任务调度系统设计思路及核心代码实现
基于Python及zookeeper实现简单分布式任务调度系统设计思路及核心代码实现 by:授客 QQ:1033553122 测试环境 功能需求 实现思路 代码实践(关键技术点实现) 代码模块组织 ...
- python 访问 zookeeper
python 访问 zookeeper zookeeper 分布式服务框架是 Apache Hadoop 的一个子项目,它主要是用来解决分布式应用中经常遇到的一些数据管理问题,如:统一命名服务.状态同 ...
- Python 基于python操纵zookeeper介绍
基于python操纵zookeeper介绍 by:授客 QQ:1033553122 测试环境 Win7 64位 Python 3.3.4 kazoo-2.6.1-py2.py3-none-any.w ...
- python连接zookeeper的日志问题
用python连接zookeeper时,在终端里,一直会有zookeeper的日志冒出来,这样会很烦. -- ::,:(: Exceeded deadline by 11ms 解决方法是在连接后设置一 ...
- python中根据字符串导入模块module
python中根据字符串导入模块module 需要导入importlib,使用其中的import_module方法 import importlib modname = 'datetime' date ...
- Python提示AttributeError 或者DeprecationWarning: This module was deprecated解决方法
Python提示AttributeError 或者DeprecationWarning: This module was deprecated解决方法 在使用Python的sklearn库时,发现sk ...
- [转]Python中出错:ImportError: No module named win32com.client
Python中出错:ImportError: No module named win32com.client [问题] [已解决]Python中处理操作Excel中的图表(Chart,Graph) 的 ...
- [py]python操作zookeeper
参考: https://blog.csdn.net/heizistudio/article/details/79568188 1.安装zookeeper zookeeper-3.4.6.tar.gz ...
随机推荐
- DTrace to Troubleshoot Java Native Memory Problems
How to Use DTrace to Troubleshoot Java Native Memory Problems on Oracle Solaris 11 Hands-On Labs of ...
- oracle分组查询
分组函数 在分组函数中,如果有一个查找项分组,其他项必须也分组,比如下面的语句会报错,因为sal分组了,而ename没有分组: 1.显示工资最高的员工: 2.显示所有员工的平均工资: 2.1使用系统函 ...
- 配置SSH免密码验证
为了防止无良网站的爬虫抓取文章,特此标识,转载请注明文章出处.LaplaceDemon/ShiJiaqi. http://www.cnblogs.com/shijiaqi1066/p/5183803. ...
- navicat 数据库管理工具快捷键
最近在使用navicat 管理数据库中,因为经常要写一些sql的,但是每次都要鼠标点击运行,感觉很不爽,于是找到navicat(以下) 快捷键(最常用的): ctrl + q 打开查询窗口 ctrl ...
- 学习使用Et采集的过程和分析
- H TML5 之 (5) 一个在线画图板
这里加入了点难度了,增加了对HTML很多时间的把握,对象的把握 index.html <!DOCTYPE HTML> <html> <head> <title ...
- SQL Server2008 附加数据库失败 错误代码5120
由于目录权限不够导致 ,解决办法:将文件所在的文件夹增加everyone 并且赋予完全控制权限问题解决
- A题笔记(3)
No. 1381 容器相关 #include <vector> 头文件 vector<Presents> present; present.push_back(name); 向 ...
- Delphi Register
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Form ...
- Struts2单文件上传
第一步:首先写个上传文件的页面(简单的一个form表单) <html> <head> <meta http-equiv="Content-Type" ...