diff options
author | Nathaniel Manista <nathaniel@google.com> | 2018-06-12 17:30:23 +0000 |
---|---|---|
committer | Nathaniel Manista <nathaniel@google.com> | 2018-06-14 17:16:04 +0000 |
commit | 8234d14113f484c60ee8633dc060f8054adf3748 (patch) | |
tree | 115e9e3d56178687028127a7d2dd457608e3ad54 /examples/python/multiplex | |
parent | a70053690a3f07ecf69ff283c288d018d2362ee4 (diff) |
Close channels in examples
Diffstat (limited to 'examples/python/multiplex')
-rw-r--r-- | examples/python/multiplex/multiplex_client.py | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/examples/python/multiplex/multiplex_client.py b/examples/python/multiplex/multiplex_client.py index 9baa10247d..19d39ce66e 100644 --- a/examples/python/multiplex/multiplex_client.py +++ b/examples/python/multiplex/multiplex_client.py @@ -106,20 +106,23 @@ def guide_route_chat(route_guide_stub): def run(): - channel = grpc.insecure_channel('localhost:50051') - greeter_stub = helloworld_pb2_grpc.GreeterStub(channel) - route_guide_stub = route_guide_pb2_grpc.RouteGuideStub(channel) - greeter_response = greeter_stub.SayHello( - helloworld_pb2.HelloRequest(name='you')) - print("Greeter client received: " + greeter_response.message) - print("-------------- GetFeature --------------") - guide_get_feature(route_guide_stub) - print("-------------- ListFeatures --------------") - guide_list_features(route_guide_stub) - print("-------------- RecordRoute --------------") - guide_record_route(route_guide_stub) - print("-------------- RouteChat --------------") - guide_route_chat(route_guide_stub) + # NOTE(gRPC Python Team): .close() is possible on a channel and should be + # used in circumstances in which the with statement does not fit the needs + # of the code. + with grpc.insecure_channel('localhost:50051') as channel: + greeter_stub = helloworld_pb2_grpc.GreeterStub(channel) + route_guide_stub = route_guide_pb2_grpc.RouteGuideStub(channel) + greeter_response = greeter_stub.SayHello( + helloworld_pb2.HelloRequest(name='you')) + print("Greeter client received: " + greeter_response.message) + print("-------------- GetFeature --------------") + guide_get_feature(route_guide_stub) + print("-------------- ListFeatures --------------") + guide_list_features(route_guide_stub) + print("-------------- RecordRoute --------------") + guide_record_route(route_guide_stub) + print("-------------- RouteChat --------------") + guide_route_chat(route_guide_stub) if __name__ == '__main__': |