From e5e218381abb6fb88892a0c0820f3695ced45e9d Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Wed, 11 Dec 2019 13:11:29 -0800 Subject: [PATCH] And the rest of helloworld --- .../python/helloworld/greeter_client_with_options.py | 7 +++---- .../helloworld/greeter_server_with_reflection.py | 11 +++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/examples/python/helloworld/greeter_client_with_options.py b/examples/python/helloworld/greeter_client_with_options.py index e9ab5508ddd..8e9287c960c 100644 --- a/examples/python/helloworld/greeter_client_with_options.py +++ b/examples/python/helloworld/greeter_client_with_options.py @@ -18,8 +18,7 @@ import logging import grpc -import helloworld_pb2 -import helloworld_pb2_grpc +protos, services = grpc.protos_and_services("helloworld.proto") def run(): @@ -33,11 +32,11 @@ def run(): options=[('grpc.lb_policy_name', 'pick_first'), ('grpc.enable_retries', 0), ('grpc.keepalive_timeout_ms', 10000)]) as channel: - stub = helloworld_pb2_grpc.GreeterStub(channel) + stub = services.GreeterStub(channel) # Timeout in seconds. # Please refer gRPC Python documents for more detail. https://grpc.io/grpc/python/grpc.html response = stub.SayHello( - helloworld_pb2.HelloRequest(name='you'), timeout=10) + protos.HelloRequest(name='you'), timeout=10) print("Greeter client received: " + response.message) diff --git a/examples/python/helloworld/greeter_server_with_reflection.py b/examples/python/helloworld/greeter_server_with_reflection.py index 7c73a42eb66..827488927ae 100644 --- a/examples/python/helloworld/greeter_server_with_reflection.py +++ b/examples/python/helloworld/greeter_server_with_reflection.py @@ -19,21 +19,20 @@ import logging import grpc from grpc_reflection.v1alpha import reflection -import helloworld_pb2 -import helloworld_pb2_grpc +protos, services = grpc.protos_and_services("helloworld.proto") -class Greeter(helloworld_pb2_grpc.GreeterServicer): +class Greeter(services.GreeterServicer): def SayHello(self, request, context): - return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name) + return protos.HelloReply(message='Hello, %s!' % request.name) def serve(): server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) - helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server) + services.add_GreeterServicer_to_server(Greeter(), server) SERVICE_NAMES = ( - helloworld_pb2.DESCRIPTOR.services_by_name['Greeter'].full_name, + protos.DESCRIPTOR.services_by_name['Greeter'].full_name, reflection.SERVICE_NAME, ) reflection.enable_server_reflection(SERVICE_NAMES, server)