Print info when server starts (#30964)

pull/30995/head
AmosWang 2 years ago committed by GitHub
parent 888c64adf8
commit 166824205e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      examples/python/helloworld/greeter_client.py
  2. 4
      examples/python/helloworld/greeter_server.py

@ -26,6 +26,7 @@ def run():
# 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.
print("Will try to greet world ...")
with grpc.insecure_channel('localhost:50051') as channel:
stub = helloworld_pb2_grpc.GreeterStub(channel)
response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'))

@ -28,10 +28,12 @@ class Greeter(helloworld_pb2_grpc.GreeterServicer):
def serve():
port = '50051'
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
server.add_insecure_port('[::]:50051')
server.add_insecure_port('[::]:' + port)
server.start()
print("Server started, listening on " + port)
server.wait_for_termination()

Loading…
Cancel
Save