From 34a3f06d91669a168c7598cb8fdd0f66ad51f5c1 Mon Sep 17 00:00:00 2001 From: jkhsjdhjs Date: Wed, 31 Jan 2024 01:01:35 +0000 Subject: [PATCH] add socket timeout + exit if connection is lost Fix #2 --- bert.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bert.py b/bert.py index fd9ddae..bdbcd3c 100755 --- a/bert.py +++ b/bert.py @@ -72,7 +72,7 @@ def connect(host, port): global irc print("Connecting to "+host+":"+str(port)) context = ssl.create_default_context() - with socket.create_connection((host, port)) as sock: + with socket.create_connection((host, port), timeout=180) as sock: irc = context.wrap_socket(sock, server_hostname=host) @@ -141,6 +141,9 @@ def me(chan, msg): def getData(): raw = irc.recv(4096) + if not raw: + print("Connection lost!") + sys.exit(0) try: data = raw.decode("UTF-8") except: