blob: c355662ef867bd5ad6b19d7002fcdcdf2e15211d [file] [log] [blame]
Jan Tattermusch7897ae92017-06-07 22:57:36 +02001# Copyright 2015 gRPC authors.
Jan Tattermusch7dfd4ab2015-02-25 15:00:46 -08002#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
Jan Tattermusch7dfd4ab2015-02-25 15:00:46 -08006#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02007# http://www.apache.org/licenses/LICENSE-2.0
Jan Tattermusch7dfd4ab2015-02-25 15:00:46 -08008#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
Jan Tattermusch7dfd4ab2015-02-25 15:00:46 -080014"""The Python implementation of the GRPC helloworld.Greeter server."""
15
Nathaniel Manista46585e22016-07-15 22:33:50 +000016from concurrent import futures
Jan Tattermusch7dfd4ab2015-02-25 15:00:46 -080017import time
18
Nathaniel Manista46585e22016-07-15 22:33:50 +000019import grpc
20
Jan Tattermusch7dfd4ab2015-02-25 15:00:46 -080021import helloworld_pb2
Nathaniel Manistac15ee832016-12-15 22:58:29 +000022import helloworld_pb2_grpc
Jan Tattermusch7dfd4ab2015-02-25 15:00:46 -080023
24_ONE_DAY_IN_SECONDS = 60 * 60 * 24
25
26
Nathaniel Manistac15ee832016-12-15 22:58:29 +000027class Greeter(helloworld_pb2_grpc.GreeterServicer):
Jan Tattermusch7dfd4ab2015-02-25 15:00:46 -080028
ncteisen848a7492017-12-12 10:31:47 -080029 def SayHello(self, request, context):
30 return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)
Jan Tattermusch7dfd4ab2015-02-25 15:00:46 -080031
32
33def serve():
ncteisen848a7492017-12-12 10:31:47 -080034 server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
35 helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
36 server.add_insecure_port('[::]:50051')
37 server.start()
38 try:
39 while True:
40 time.sleep(_ONE_DAY_IN_SECONDS)
41 except KeyboardInterrupt:
42 server.stop(0)
43
Jan Tattermusch7dfd4ab2015-02-25 15:00:46 -080044
45if __name__ == '__main__':
ncteisen848a7492017-12-12 10:31:47 -080046 serve()