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()