1 编译(保留了C和python语言,简化编译)

# ./configure --without-java --without-cpp --without-php --without-erlang

#make && make install

2 安装python thrift模块

#easy_install thrift

3 生成协议(python)示例来之于http://thrift.apache.org/tutorial/py, 记得第二步中两个文件都要下载

#thrift -r --gen c tutorial.thrift

生成了gen-py文件夹,

4 执行验证 - 示例python脚本下载到thrift-0.9.1/lib/py目录中,gen-py文件夹也mv过来

# python thrift-server.py
Starting the server...
ping()
add(1,1)
calculate(1, Work(comment=None, num1=1, num2=0, op=4))
calculate(1, Work(comment=None, num1=15, num2=10, op=2))
getStruct(1)

# python thrift-client.py
ping()
1+1=2
InvalidOperation: InvalidOperation(what=4, why='Cannot divide by 0')
15-10=5
Check log: 5

注释:thrift依赖请查看http://thrift.apache.org/docs/install/, python不依赖特殊的库(如C++依赖boost),Requirements for building from source提到的依赖可以从搜索引擎查找代码,编译就是简单的./configure && make && make install

操作系统:centos

thrift版本:0.9.1

python: 2.7

posted on 2014-08-22 17:46  #hanhui  阅读(538)  评论(0编辑  收藏  举报