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 ...
随机推荐
- Android自定义DataTimePicker(日期选择器)
实现的效果就是在同一个布局上显示日期选择和时间选择,时间不准确bug修复 1.自定义类DateTimePickDialogUtil.java public class DateTimePickDial ...
- nginx同时监听本机ipv4/ipv6端口
修改nginx.conf配置文件 server { listen ; listen [::]:; } 0.0.0.0 表示本机所有ipv4地址,需要监听特定地址替换即可 [::] 表示本机所有ip ...
- skip-grant-tables
1.net stop mysql 2.my.ini中[mysqld]plugin_dir的下面增加skip-grant-tables 3.net start mysql 4.在Navicat中打开my ...
- JavaScript单例模式
一.什么是单例 意思是指获取的对象只有一份. 二.最通用的单例 任何时刻获取SingLeton.instance都是同一个对象 var SingLeton={ instance:{ property: ...
- 31、三层架构、AJAX+FormsAuthentication实现登陆
三层架构 前段时间公司要求修改一个网站,打开后我疯了,一层没有都是调用的DB接口,遍地的SQL语句,非常杂乱. 什么是三层架构? 三层架构是将整个项目划分为三个层次:表现层.业务逻辑层.数据访问层.目 ...
- c语言训练题:关于张三李四王五说谎的问题(此处用javascript实现)
(第一篇博文) 今天在一个交流群里见他们无聊,然后找到之前收藏的一些c语言题目放出去想让他们做,结果反倒是自己不会做,于是花了很多时间去想. 原题:张三说李四在说谎,李四说王五在说谎,王五说张三和李四 ...
- Library中的title与Name
在Library中新增Title字段,其中文件夹的title字段与Name相同,并且默认生成:但是文件的Title字段为空.
- Android学习之旅:五子棋
在学完了Android的基础之后,我开始尝试着写一些小项目练练手,同时进一步巩固自己的基础知识,而我选的的第一个项目就是做一个简单的人人对战的五子棋小游戏. 首先,我们要新建一个自定义控件类Panel ...
- iOS崩溃报告获取二
// // JKExceptionHandler.h // JKExceptionHandler // // Created by Jack on 16/9/7. // Copyright © 201 ...
- WPF中TreeView数据结构解析
XAML.CS代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; usi ...