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是数据格式调用的文件

py  xx_pb2_grpc.pgrpc传输协议接口调用的文件

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文件的根目录下

参考:

https://grpc.io/docs/quickstart/python.html

猜你喜欢

转载自blog.csdn.net/weixin_38383877/article/details/81104371
今日推荐