1. 配置好python环境后安装thrift库
cd thrift/lib/
pip install -e py
2. 将tutorial.thrift、shared.thrift转成python代码
thrift -r --gen tutorial.thrift
#会产生gen-py
#将产生的gen-py拷贝到python测试代码所在目录
cp -r gen-py <thrift/tutorial/py>
3. 启动server
cd thrift/tutorial/py
./PythonServer.py
#显示
(djangodev) ➜ py ./PythonServer.py
Starting the server...
ping()
add(1,1)
calculate(1, Work(num1=1, num2=0, op=4, comment=None))
calculate(1, Work(num1=15, num2=10, op=2, comment=None))
getStruct(1)
4. 启动client
cd thrift/tutorial/py
./PythonClient.py
#显示
(djangodev) ➜ py ./PythonClient.py
ping()
1+1=2
InvalidOperation: InvalidOperation(whatOp=4, why='Cannot divide by 0')
15-10=5
Check log: 5
网友评论