Thrift Python in windows
来源:互联网 发布:2017西安程序员工资 编辑:程序博客网 时间:2024/06/06 03:22
一:安装
1. 去官网下载thrift.exe
http://thrift.apache.org/download/
2. 放到环境变量里面去
在cmd中直接输入thrift可以运行。
3. 下载Thrift Python Software Library
https://pypi.python.org/pypi/thrift/0.9.0
4. 解压,然后进入目录,执行:python setup.py install
二:测试
1. thrift文件
service Executer{bool add_measure_group(1: string str_addr, 2: i32 interval);bool del_measure_group(1: string str_addr, 2: i32 interval);}
2. thrift生成py
thrift -gen py calcute_server.thrift
3. 写server端程序
import syssys.path.append('./gen-py')from calcute_server import Executerfrom calcute_server.ttypes import *from thrift.transport import TSocketfrom thrift.transport import TTransportfrom thrift.protocol import TBinaryProtocolfrom thrift.server import TServerimport socketclass ExecuterHandler:def __init__(self):self.log = {}def add_measure_group(self, addr, interval):print "add"return Truedef del_measure_group(self, addr, interval):print "del"return Truehandler = ExecuterHandler()processor = Executer.Processor(handler)transport = TSocket.TServerSocket("localhost",9000)tfactory = TTransport.TBufferedTransportFactory()pfactory = TBinaryProtocol.TBinaryProtocolFactory()server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)print "Starting python server..."server.serve()print "done!"
4. 写client端程序
import syssys.path.append('./gen-py')from calcute_server import Executerfrom calcute_server.ttypes import *from calcute_server.constants import *from thrift import Thriftfrom thrift.transport import TSocketfrom thrift.transport import TTransportfrom thrift.protocol import TBinaryProtocoltry:# Make sockettransport = TSocket.TSocket('localhost', 9000)# Buffering is critical. Raw sockets are very slowtransport = TTransport.TBufferedTransport(transport)# Wrap in a protocolprotocol = TBinaryProtocol.TBinaryProtocol(transport)# Create a client to use the protocol encoderclient = Executer.Client(protocol)# Connect!transport.open()client.add_measure_group("ff15::1", 100)print 'done!'transport.close()except Thrift.TException, tx:print "%s" % (tx.message)
5. 目录结构
6. 结果
>python ExecuteServer.pyStarting python server...
>python ExecuteClient.pydone!
>python ExecuteServer.pyStarting python server...add
三:其他
其他语言thrift在windows上没有研究。
可以参考:http://thrift.apache.org/docs/install/windows/
- Thrift Python in windows
- Thrift in python
- Thrift in python<转>
- thrift python
- Python thrift
- python -mtimeit in windows
- windows下编译thrift
- windows下使用thrift
- Windows安装、测试Thrift
- thrift windows vs2015编译
- thrift for python部署
- CentOS thrift python demo
- python thrift 示例
- thrift python安装
- python thrift 示例<转>
- thrift总结(python)
- Python&Thrift--Server&Client
- python thrift简单例子
- #define
- MySQL体系结构
- WebView cookies清理
- MySQL 使用笔记
- 九度OJ 题目1470:调整方阵
- Thrift Python in windows
- 深入探索-JAVA内存管理
- 浏览器内核分类
- 验证对象中属性是否为null
- Java中对于main函数的理解
- 西北工业大学计算机研究生机试真题
- js日期时间函数
- JAVA学习(一)__操作FTP
- 运行jetty程序