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 ...
随机推荐
- javascript、jsp
1.javascript:简称js 在<body>与 </body>之间 加入<script> </script>即可 最好在<head>与 ...
- 利用Gulp实现JSDoc 3的文档编写过程中的实时解析和效果预览
### 利用Gulp实现JSDoc 3的文档编写过程中的实时解析和效果预览 http://segmentfault.com/a/1190000002583569
- Linux查看系统负载常用命令
1.查看负载 uptime :: up day, :, user, load average: 0.00, 0.00, 0.00 在过去1分钟.5分钟.15分钟内平均进程数量 2.查看用户 w :: ...
- linux下安装apache2.2.27
1.首先下载httpd-2.2.27.tar.gz用linux命令下载 wget http://mirrors.cnnic.cn/apache//httpd/httpd-2.2.27.tar.gz 2 ...
- jQuery Validate 插件
>>>>>>>>>>>>>>>>>>>>>>>>> ...
- JS DOM 来控制HTML元素
JS DOM 来控制HTML元素 (ps:这个有很多方法,挑一些详解,嘻嘻) 1.getElementsByName():获取name. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ...
- 使用bind()扩充作用域
window.color = "blue"; var o = {color :"red"}; function sayColor(){ alert(this.c ...
- Angularjs中编写指令模版
angular.module('moduleName', []).directive( 'namespaceDirectiveName', [ function() { return { restri ...
- Windows phone 之手势识别(Drag)
首先,在XAML页面中,添加如下代码: 前提,别忘了添加 1.引入dll (silverlight for wndows phone toolkit) 2.引入命名空间 xmlns:toolkit=& ...
- 《Velocity java开发指南》中文版(下)转载
文章出自:http://sakyone.iteye.com/blog/524292 8.Application Attributes Application Attributes (应用程序属性)是和 ...