python gRPC测试helloworld
一、測試helloworld
1、在https://github.com/grpc/grpc 下載example
2、用cmd打開命令行,cd到helloworld的根目錄
cd E:\pythoncode\gRPC\grpc-master\grpc-master\examples\python\helloworld
然后運行?python greeter_server.py
3、再用cmd打開另一個命令行。同樣cd到helloworld的根目錄
然后運行python greeter_client.py
4、即可在greeter_server.py界面看到Greeter client received: Hello, you!
二、更新gRPC服務
1、對helloworld.proto進行修改后,必須運行cmd
即打開命令行,cd到helloworld.proto和helloworld文件的根目錄下(如果顯示No such director,則到helloworld的根目錄下)
然后運行?python -m grpc_tools.protoc -I../../protos --python_out=. --grpc_python_out=. ../../protos/helloworld.proto
生成兩個文件:
xx_pb2.py是數據格式調用的文件,用來和 protobuf 數據進行交互
py ?xx_pb2_grpc.pgrpc傳輸協議接口調用的文件,用來和 grpc 進行交互
2、cd到helloworld的根目錄
cd E:\pythoncode\gRPC\grpc-master\grpc-master\examples\python\helloworld
然后運行?python greeter_server.py
3、再用cmd打開另一個命令行。同樣cd到helloworld的根目錄
然后運行python greeter_client.py
4、即可在greeter_server.py界面看到
Greeter client received: Hello, you!
Greeter client received: Hello again, you!
注意:要運行python -m grpc_tools.protoc -I../../protos --python_out=. --grpc_python_out=. ../../protos/helloworld.proto
時,目錄必須為helloworld.proto或者helloworld.proto和helloworld文件的根目錄下
參考:
python -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. ./data.proto
?
https://grpc.io/docs/quickstart/python.html
總結
以上是生活随笔為你收集整理的python gRPC测试helloworld的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mitmproxy抓包 | Python
- 下一篇: 求最大公约数——辗转相除法