def main(): chanel = grpc.insecure_channel('localhost:8080') # 使用Stub client = pi_pb2_grpc.PiCalculatorStub(chanel) # 调用 for i in range(100000000000): client.Calc(pi_pb2.PiRequest(n=i))
def main(): channel = grpc.insecure_channel('localhost:8080', chan_ops) client = pi_pb2_grpc.PiCalculatorStub(channel) for i in range(10): try: res = client.Calc(pi_pb2.PiRequest(n=i)) print "pi(%d) =" % i, res.value except grpc.RpcError as e: print e.code(), e.details()
def main(): channel = grpc.insecure_channel('localhost:8080') client = pi_pb2_grpc.PiCalculatorStub(channel) for i in range(0, 1000): try: print('pi(%d) =' % i, client.Calc(pi_pb2.PiRequest(n=i), timeout=5).value) except grpc.RpcError as e: print(e.code()) print(e.details())
def main(): # channel = grpc.insecure_channel('localhost:8080') chan_ops = [('grpc.default_compression_algorithm', CompressionAlgorithm.gzip), ('grpc.grpc.default_compression_level', CompressionLevel.high)] channel = grpc.insecure_channel('localhost:8080', chan_ops) client = pi_pb2_grpc.PiCalculatorStub(channel) for i in range(2): try: print "pi(%d) =" % i, client.Calc(pi_pb2.PiRequest(n=i), timeout=5).value except grpc.RpcError as e: # print e.code(), e.details() print e.code(), e.initial_metadata()
def pi(client, k): return client.Calc(pi_pb2.PiRequest(n=k)).value
def generate_request(): for i in range(1, 100): yield pi_pb2.PiRequest(n=i)
def main(): channel = grpc.insecure_channel('localhost:8080') client = pi_pb2_grpc.PiCalculatorStub(channel) for i in range(1, 1000): print "pi(%d) = " % i, client.Calc(pi_pb2.PiRequest(n=i)).value