from concurrent import futures import socket import time import grpc import grpcdemo_pb2 import grpcdemo_pb2_grpc import subprocess ONE_DAY = 60 * 60 * 24 # Sleep time in seconds PORTNO = 6000 class HostCommand(grpcdemo_pb2_grpc.HostCommandServicer): def runcommand(self, request, context): return grpcdemo_pb2.Results(results=subprocess.check_output(request.command.split())) def serve(): server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) grpcdemo_pb2_grpc.add_HostCommandServicer_to_server(HostCommand(), server) server.add_insecure_port('[::]:%s' % PORTNO) server.start() try: while True: time.sleep(ONE_DAY) except KeyboardInterrupt: server.stop(0) if __name__ == '__main__': serve()