【问题标题】:What's the difference between gRPC and Beta gRPC classes?gRPC 和 Beta gRPC 类有什么区别?
【发布时间】:2017-03-07 12:21:58
【问题描述】:

我有以下 proto 文件,它将生成一个 _pb2.py 文件以在 python 中使用。

syntax = "proto3";
service Calculator {
    rpc Add (AddRequest) returns (AddReply) {}
}
message AddRequest{ 
    int32 n1=1;
    int32 n2=2;
}

message AddReply{
    int32 n1=1;
}

_pb2.py protoc 中会生成:

...
class CalculatorServicer(object):
  def Add(self, request, context):
    context.set_code(grpc.StatusCode.UNIMPLEMENTED)
    context.set_details('Method not implemented!')
    raise NotImplementedError('Method not implemented!')

class BetaCalculatorServicer(object):
  def Add(self, request, context):
    context.code(beta_interfaces.StatusCode.UNIMPLEMENTED)
...

我想知道这两个类(CalculatorServicerBetaCalculatorServicer)之间的区别及其用法。

我见过使用第一个类的代码和使用第二个类的代码。

【问题讨论】:

    标签: python grpc


    【解决方案1】:

    您应该使用不合格的代码元素(特别是 _pb2_grpc.py 文件中的那些代码元素),而不是 _pb2.py 文件中的 Beta 代码元素。如果您使用最新版本的代码生成器生成_pb2.py_pb2_grpc.py 文件(请尝试使用绝对最新的grpcio-tools,当前为1.1.3),您应该会看到doc strings on the Beta code elements in the generated code describing them as deprecated and to be removed in the future

    Our examples 显示生成的_pb2_pb2_grpc 模块的当前预期用途。

    【讨论】:

      猜你喜欢
      • 2016-06-12
      • 2017-11-11
      • 2018-12-28
      • 2020-10-11
      • 2020-03-05
      • 2016-12-26
      • 1970-01-01
      • 2017-08-30
      • 2018-09-18
      相关资源
      最近更新 更多