0

I have written a code for handling multiple requests at a time but my server freezes randomly after a while, is there any way to check and restart the server if there is no activity.

class MyTCPHandler(socketserver.BaseRequestHandler):

    def handle(self):
        self.data = self.request.recv(1024).strip()
        #doing some work and generating response
        self.request.sendall(response)

if __name__ == "__main__":
    HOST, PORT = "0.0.0.0", 4879

    socketserver.TCPServer.allow_reuse_address = True
    with socketserver.TCPServer((HOST, PORT), MyTCPHandler) as server:
        
        try:
            server.serve_forever()
        except KeyboardInterrupt:
            server.shutdown()
            server.socket.close()
martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

0

via bash if you want to stop the server ps aux|grep The name of the program|awk '{print $2}'|xargs kill

Luca Sans S
  • 118
  • 8