开发步骤说明

【任务1】调通单机版的thrift-python版本

安装thrift

  • 下载源码包

    wget http://apache.fayea.com/thrift/0.9.3/thrift-0.9.3.tar.gz

  • 安装thrift [进入thrift目录]

    • 运行命令: yum install openssl-devel.x86_64 [可选择是否安装]
    • 运行命令: yum install boost-devel.x86_64 [必须安装]
    • 运行命令: ./configure --with-cpp --with-boost --with-python --without-csharp --with-java --without-erlang --without-perl --with-php --without-php_extension --without-ruby --without-haskell --without-go
    • 运行命令: yum install boost-devel-static
    • 运行命令: make,make isntall
  • 安装thrift对python的支持模块

    pip install thrift==0.9.3

创建thrift模块文件并编译

  1. 创建RecSys.thrift文件 [创建到任意目录]
service RecSys {
string rec_data(1:string data)
}
  1. 命令:thrift --gen py RecSys.thrift,此时在当前目录中会产生gen-py的文件夹,其中有当前的模块名字

开发python版的client和server

  • 创建 server.py 文件测试
import sys
sys.path.append('../schema/gen-py/') from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from RecSys import RecSys
from thrift.server import TServer
from RecSys.ttypes import * class RecSysHandler(RecSys.Iface):
def rec_data(self, a):
print "Receive: %s" %(a)
return "I`m OK !!!" if __name__ == "__main__": # 实例化handler
handler = RecSysHandler() # 设置processor
processor = RecSys.Processor(handler) # 设置端口
transport = TSocket.TServerSocket('localhost', port=9900) # 设置传输层
tfactory = TTransport.TBufferedTransportFactory() # 设置传输协议
pfactory = TBinaryProtocol.TBinaryProtocolFactory()
handler = RecSysHandler() server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) print 'Starting the server...'
server.serve()
print 'done'
  • 创建 client.py 文件测试
#coding=utf-8

import sys
sys.path.append('../schema/gen-py/') from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from RecSys import RecSys if __name__ == "__main__": # 设置端口
transport = TSocket.TSocket('localhost', port=9900) # 设置传输层
transport = TTransport.TBufferedTransport(transport) # 设置传输协议
protocol = TBinaryProtocol.TBinaryProtocol(transport) client = RecSys.Client(protocol) transport.open() rs = client.rec_data("are you ok ??")
print "receive return data: ", rs transport.close()

【一】调通单机版的thrift-python版本的更多相关文章

  1. 【二】调通单机版的thrift-C++版本

    [任务2]调通单机版的thrift-C++版本 [任务2]调通单机版的thrift-C++版本 创建文件 安装boost开发工具 拷贝文件 [可忽略此步骤,如果c++代码直接编译无误的话] 编译 创建 ...

  2. 全志R58平台调通s5k5eya(RAW+MIPI)

    全志R58平台调通s5k5eya(RAW+MIPI) 2017/5/31 10:30 版本:V1.1 1.前期使用的是s5k5eyx的ISP的固件/tuning 文件 Y:\s5k5eya_r58_d ...

  3. CentOS7 下升级Python版本

    来博客园的第一篇博客,以后要坚持养成记录.分享的习惯啊,这样生活才会有痕迹~ 服务器版本:CentOS 7.3 64位 旧Python版本:2.7.5 新Python版本:3.8.0 说明:本次配置使 ...

  4. 2016最后一贴,终于调通一个测试示例,并发现一个BUG???

    真的难点在于第一次调通.纠结五天,终于搞出界面. 也发现了一个书上代码,编辑用户时死活不通的情况,我将Links去了,改在data里,我X,,全OK了.. 原来的代码: onAdd: function ...

  5. 提取bmp图片的颜色信息,可直接framebuffer显示(c版本与python版本)

    稍微了解了下linux的framebuffer,这是一种很简单的显示接口,直接写入像素信息即可 配置好的内核,会有/dev/fbn 的接口,于是想能否提前生成一个文件,比如logo.fb,里面仅包含像 ...

  6. Centos7下安装python,查看python版本

    安装Centos的时候,一般会自带默认安装python2.x 一般用python -V可以查看python版本. 我当时安装的时候,运行了那个语句,但是却显示了一大堆出来,虽然里面也带有版本信息,但是 ...

  7. LInux升级Python版本2.7.11所遇问题汇总

    首先请原谅我使用校园网络,基本上打不开谷歌,网络搜取得帮助均来自度娘. 对于我这个linux新手 IT 新手来说,自己升级点东西好担心,万一出错,可能都要重来.... 参照度娘内容和自己摸索,今天晚上 ...

  8. Sublime Text 2 增加python版本

    当系统中装有多个python版本时,Sublime Text 2  使用哪个版本需要手动添加 键入一下内容,path输入python的安转路径 保存至Python27.sublime-build文件 ...

  9. linux 多个python版本的切换

    源码安装新的python版本,我的安装路径: /usr/self/Python3.5.2 修改软链接到你所安装的python版本中: 默认python命令是在/usr/bin/目录下 1 sudo m ...

随机推荐

  1. 立即终止Sleep的线程

    在实际工作中,我们需要每隔几分钟从API取数. while(isRunning) { work(); Thread.Sleep(5*60*1000); } 如果设置isRunning=false,也需 ...

  2. IE浏览器兼容问题(下)——IE6的常见问题

    IE6常见兼容性问题 1.盒模型问题 (1)DTD问题 DTD:文档定义类型,规定了要遵循的书写规范. 如果不写DTD,高级浏览器还是可以正常加载,IE6会以怪异模式进行加载. 盒模型:正常应该是外扩 ...

  3. OC基础数据类型-NSDictionary

    1.字典NSDictionary 字典与数组的区别:数组讲究顺序,而字典可以快速帮助我们找到数据,数据是我们的目的,键是我们的手段 NSDictionary *dict = [[NSDictionar ...

  4. python进阶介绍(进阶1)

    转载请标明出处: http://www.cnblogs.com/why168888/p/6411664.html 本文出自:[Edwin博客园] python进阶介绍(进阶1) 1. python基础 ...

  5. .NET Core学习之路

    1.NET Core环境搭建 安装.NET Core: .NET Core 包括.NET Core Runtime 和 .NET Core SDK: NET Core = 应用运行依赖的 .NET C ...

  6. Jenkins报错Caused: java.io.IOException: Cannot run program "sh" (in directory "D:\Jenkins\Jenkins_home\workspace\jmeter_test"): CreateProcess error=2, 系统找不到指定的文件。

    想在本地执行我的python文件,我本地搭建了一个Jenkins,使用了execute shell来运行我的脚本,发现报错 [jmeter_test] $ sh -xe D:\tomcat\apach ...

  7. 使用jmeter使用Jenkins发送自定义消息内容

    Jenkins运行成功后,需要发送消息给用户,自己封装了一个rtx的方法,进行发送,配置方法如下: 1.在windows下选择 execute windows batch command,执行我的py ...

  8. non-fragile:oc2.0特性

    Runtime Versions and Platforms There are different versions of the Objective-C runtime on different ...

  9. luogu P2016 战略游戏

    嘟嘟嘟 树形dp水题啦. 刚开始以为和[SDOI2006]保安站岗这道题一样,然后交上去WA了. 仔细想想还是有区别的,一个是能看到相邻点,一个是能看到相邻边.对于第一个,可以(u, v)两个点都不放 ...

  10. PHP------知识复习

    PHP概述 (1)PHP(Hypertext  Perprocessor)超级文本预处理器 (2) PHP是一种在服务器端执行的嵌入HTML文档的脚本语言 (3) 是一种网站开发语言(B/S结构) ( ...