如何使用proto3在Python中创建gRPC服务器?

问题描述:

根据此http://www.grpc.io/docs/tutorials/basic/python.html#creating-the-server和这里的示例https://github.com/grpc/grpc/tree/v1.0.0/examples/python/route_guide,当我生成我的_pb2.py文件时,应该创建几个名为*Stub*Servicer的类。但是,我生成的_pb2.py文件不包含任何此类内容。如何使用proto3在Python中创建gRPC服务器?

这是我生成我_pb2.py文件:

protoc --proto_path=.venv/lib/python3.5/site-packages/grpc/tools/_proto/ --proto_path=. --python_out=voyager/ voyager.proto 

有什么特别之处proto3这意味着不会产生这些类?或者我错过了一个protoc标志?我似乎无法弄清楚如何创建一个gRPC服务器。

看起来你好像缺少了--grpc_python_out=voyager/。有两个插件:Protobuf Python和gRPC Python。你只运行Protobuf。