From a4f5c90f41a602ff13e7d635133184cb50efa018 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 11 Jul 2023 19:49:07 +0200 Subject: [PATCH] Tweak to prevent a busy-loop that happens when the TCP connection to the server is closed. --- pyncraft/connection.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pyncraft/connection.py b/pyncraft/connection.py index c42add6..43214f8 100644 --- a/pyncraft/connection.py +++ b/pyncraft/connection.py @@ -8,6 +8,9 @@ class RequestError(Exception): pass +class ConnectionError(Exception): + pass + class Connection: """Connection to a Minecraft Pi game""" RequestFailed = "Fail" @@ -24,6 +27,8 @@ def drain(self): if not readable: break data = self.socket.recv(1500) + if len(data) == 0: + raise ConnectionError("%s failed! Cause: connection closed" % self.lastSent.strip()) e = "Drained Data: <%s>\n"%data.strip() e += "Last Message: <%s>\n"%self.lastSent.strip() sys.stderr.write(e)