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.

This commit is contained in:
Firepup Sixfifty 2023-10-25 20:55:39 -05:00
parent 99b393a2b5
commit 1dbd95bb1e
2 changed files with 11 additions and 6 deletions

13
core.py
View file

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

View file

@ -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