added implementation of server

This commit is contained in:
Dan Sanche 2018-06-14 12:45:44 -07:00
parent 0844d37872
commit 9c6f36c605

View file

@ -1,5 +1,29 @@
import grpc
import demo_pb2
import demo_pb2_grpc
from concurrent import futures
import time
print("Hello World")
class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer):
def ListRecommendations(self, request, context):
response = demo_pb2.ListRecommendationsResponse()
return response
if __name__ == "__main__":
# create gRPC server
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
# add class to gRPC server
demo_pb2_grpc.add_RecommendationServiceServicer_to_server(RecommendationService(), server)
# start server
print("Listening on port 8080")
server.add_insecure_port('[::]:8080')
server.start()
# keep alive
try:
while True:
time.sleep(86400)
except KeyboardInterrupt:
server.stop(0)