首页 > 编程语言 >【Thrift】python 例子

【Thrift】python 例子

时间:2022-11-11 12:02:20浏览次数:29  
标签:protocol python server 例子 print import Thrift transport thrift


service MyService{
string get()
}
import socket
import sys
sys.path.append('./gen-py')

from helloworld import MyService
from helloworld.ttypes import *

from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer

class HelloWorldHandler:
def get(self):
return "glgl"

handler = HelloWorldHandler()
processor = MyService.Processor(handler)
transport = TSocket.TServerSocket("localhost", 9090)
tfactory = TTransport.TBufferedTransportFactory()
pfactory = TBinaryProtocol.TBinaryProtocolFactory()

server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)

print("Starting thrift server in python...")
server.serve()
print("done!")


import sys
sys.path.append('./gen-py')

from helloworld import MyService

from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol

try:
transport = TSocket.TSocket('localhost', 9090)
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = MyService.Client(protocol)
transport.open()

print("client - get")
print("server - " + client.get())

transport.close()

except Thrift.TException:
print()



标签:protocol,python,server,例子,print,import,Thrift,transport,thrift
From: https://blog.51cto.com/u_15873544/5844110

相关文章

  • python 小脚本
    1.乘法口诀表foriinrange(1,10):forjinrange(1,i+1):ji=i*jprint("{}*{}={}".format(i,j,ji),end='\t')print()2.11点游戏'......
  • 一个简单的步骤让你的 Python 代码更干净
    说起来容易做起来难,我们都知道代码可读性非常重要,但是写的时候总是随心所欲,不考虑类型提示、import排序、PEP8规范。今天分享一个小技巧,通过一个简单的步骤就可以让你的......
  • 老版本Python3.6 安装踩坑
    因业务需要安装老版本的python3.6.7,当前系统默认的python2.7brew安装的3.7 brew回退安装3.6.*版本的方式,网络上有很多。比较靠谱的可以用官网方式安装,见 ​​ht......
  • python和shell产生随机密码,哪个更方便
    一、Python#@File:生成随机密码.py#@desc:importstringimportrandom####侯选all_words=list(string.ascii_lowercase+string.ascii_uppercase+string.digits......
  • 【Linux】Ubuntu 18.04 Python修改 pip源为阿里源
    1.在home/用户名/目录下创建.pip文件夹cd~mkdir.pipcd~/.piptouchpip.conf2.编辑pip.conf文件,输入以下内容保存即可[global]trusted-host=mirrors.ali......
  • python語音播報
    安装pipinstallpyttsx3pipinstallpydub代碼#语音播报模块importpyttsx3#aiff文件转换成mp3编码文件模块frompydubimportAudioSegment#模块初始化......
  • 新的学习历程-python4 input
    1num=input("请输入数字:")#input用于录入键盘输入2print(num)3print(type(num))#input获取到数据类型是字符类型45print(num+10)#报错,不能把字符和数字作......
  • 如何只获取当前项目中的python依赖包?
    我们都知道获取环境中的所有依赖包命令:pipfreeze>./requirements.txt但是,如果我们仅仅想获取当前项目中的安装包,我们可以使用pipreqs工具安装:pipinstallpipreq......
  • stable-diffusion-webui+NovelAI+Python+Git+CUDA本地部署(2G显存,使用cpu运行)
    参考原文1:https://blog.csdn.net/weixin_62651190/article/details/127666631参考原文2:https://blog.csdn.net/yefufeng/article/details/127719952环境准备Python:3.10.......
  • 拓端数据tecdat|Python代写数据可视化-seabornIris鸢尾花数据
    首先介绍一下Iris鸢尾花数据集,内容摘自百度百科:Iris数据集是常用的分类实验数据集,由Fisher,1936收集整理。“Iris也称鸢尾花卉数据集,是一类多重变量分析的数据集。数据集包......