From 1dbd95bb1e69564b38449d8cf53a5ebdbd56c741 Mon Sep 17 00:00:00 2001 From: Firepup Sixfifty Date: Wed, 25 Oct 2023 20:55:39 -0500 Subject: [PATCH] Fix RAM leak when the bot gets a ping timeout, fix outdated restart call, and move to individual thread restarts rather than whole bot reboots. --- core.py | 13 ++++++++----- ircbot.py | 4 +++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/core.py b/core.py index 8543a83..223bb95 100644 --- a/core.py +++ b/core.py @@ -23,18 +23,21 @@ def is_dead(thr): thr.join(timeout=0) return not thr.is_alive() +def start(): + t = Thread(target=launch, args=(server,)) + t.daemon = True + t.start() + return t if __name__ == "__main__": print("[LOG][CORE] Begin initialization") for server in servers: - t = Thread(target=launch, args=(server,)) - t.daemon = True - threads[server] = t - t.start() + threads[server] = start(server) print("[LOG][CORE] Started all instances. Idling...") while 1: sleep(10) for server in threads: t = threads[server] if is_dead(t): - exit(f"[EXIT][CORE] The thread for {server} died") + print(f"[LOG][CORE] The thread for {server} died, restarting it...") + threads[server] = start(server) diff --git a/ircbot.py b/ircbot.py index 41bfdf0..520ba40 100644 --- a/ircbot.py +++ b/ircbot.py @@ -366,7 +366,7 @@ def main(): for i in channels: sendmsg("Rebooting...", i) ircsock.send(bytes("QUIT :Rebooting\n", e)) - __import__("os").system("python3 -u ircbot.py") + __import__("os").system(f"python3 -u ircbot.py {server}") exit(f"[EXIT][{server}] Inner layer exited or crashed") elif ( name.lower() in adminnames and message.rstrip().lower() == exitcode @@ -415,6 +415,8 @@ def main(): ping(ircmsg) if ircmsg.find("Closing Link") != -1: exit(f"[EXIT][{server}] I got killed :'(") + if ircmsg.find("ERROR :Ping timeout: ") != -1: + exit(f"[EXIT][{server} Ping timeout]") except KeyboardInterrupt: pass