aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/python/helloworld
diff options
context:
space:
mode:
authorGravatar Nathaniel Manista <nathaniel@google.com>2018-06-12 17:30:23 +0000
committerGravatar Nathaniel Manista <nathaniel@google.com>2018-06-14 17:16:04 +0000
commit8234d14113f484c60ee8633dc060f8054adf3748 (patch)
tree115e9e3d56178687028127a7d2dd457608e3ad54 /examples/python/helloworld
parenta70053690a3f07ecf69ff283c288d018d2362ee4 (diff)
Close channels in examples
Diffstat (limited to 'examples/python/helloworld')
-rw-r--r--examples/python/helloworld/greeter_client.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/examples/python/helloworld/greeter_client.py b/examples/python/helloworld/greeter_client.py
index a0aeb47bd7..24b49ac233 100644
--- a/examples/python/helloworld/greeter_client.py
+++ b/examples/python/helloworld/greeter_client.py
@@ -22,9 +22,12 @@ import helloworld_pb2_grpc
def run():
- channel = grpc.insecure_channel('localhost:50051')
- stub = helloworld_pb2_grpc.GreeterStub(channel)
- response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'))
+ # 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:
+ stub = helloworld_pb2_grpc.GreeterStub(channel)
+ response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'))
print("Greeter client received: " + response.message)