rescuing CPU from endless loop hell on interactive console

This commit is contained in:
evilchili 2024-03-08 14:40:44 -08:00
parent d2f4a85cd5
commit 912d3fccd7

View File

@ -45,18 +45,20 @@ class RequestHandler(socketserver.StreamRequestHandler):
""" """
while True: while True:
self.data = self.rfile.readline().strip().decode() self.data = self.rfile.readline().strip().decode()
logger.debug(f"{self.data = }")
try: try:
cmd = self.data[0:4].strip().upper() cmd = self.data[0:4].strip().upper()
args = self.data[5:] args = self.data[5:]
except IndexError: except IndexError:
self.send(f"ERR Command not understood '{cmd}'") self.send(f"ERR Command not understood '{cmd}'")
sleep(0.001)
continue continue
if not cmd: if not cmd:
sleep(0.001)
continue continue
elif cmd not in self.supported_commands: elif cmd not in self.supported_commands:
self.send(f"ERR Unknown Command '{cmd}'") self.send(f"ERR Unknown Command '{cmd}'")
sleep(0.001)
continue continue
elif cmd == "KTHX": elif cmd == "KTHX":
return self.send("KBAI") return self.send("KBAI")