forked from Firepup650/FireBot
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:
parent
99b393a2b5
commit
1dbd95bb1e
2 changed files with 11 additions and 6 deletions
13
core.py
13
core.py
|
@ -23,18 +23,21 @@ def is_dead(thr):
|
||||||
thr.join(timeout=0)
|
thr.join(timeout=0)
|
||||||
return not thr.is_alive()
|
return not thr.is_alive()
|
||||||
|
|
||||||
|
def start():
|
||||||
|
t = Thread(target=launch, args=(server,))
|
||||||
|
t.daemon = True
|
||||||
|
t.start()
|
||||||
|
return t
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("[LOG][CORE] Begin initialization")
|
print("[LOG][CORE] Begin initialization")
|
||||||
for server in servers:
|
for server in servers:
|
||||||
t = Thread(target=launch, args=(server,))
|
threads[server] = start(server)
|
||||||
t.daemon = True
|
|
||||||
threads[server] = t
|
|
||||||
t.start()
|
|
||||||
print("[LOG][CORE] Started all instances. Idling...")
|
print("[LOG][CORE] Started all instances. Idling...")
|
||||||
while 1:
|
while 1:
|
||||||
sleep(10)
|
sleep(10)
|
||||||
for server in threads:
|
for server in threads:
|
||||||
t = threads[server]
|
t = threads[server]
|
||||||
if is_dead(t):
|
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)
|
||||||
|
|
|
@ -366,7 +366,7 @@ def main():
|
||||||
for i in channels:
|
for i in channels:
|
||||||
sendmsg("Rebooting...", i)
|
sendmsg("Rebooting...", i)
|
||||||
ircsock.send(bytes("QUIT :Rebooting\n", e))
|
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")
|
exit(f"[EXIT][{server}] Inner layer exited or crashed")
|
||||||
elif (
|
elif (
|
||||||
name.lower() in adminnames and message.rstrip().lower() == exitcode
|
name.lower() in adminnames and message.rstrip().lower() == exitcode
|
||||||
|
@ -415,6 +415,8 @@ def main():
|
||||||
ping(ircmsg)
|
ping(ircmsg)
|
||||||
if ircmsg.find("Closing Link") != -1:
|
if ircmsg.find("Closing Link") != -1:
|
||||||
exit(f"[EXIT][{server}] I got killed :'(")
|
exit(f"[EXIT][{server}] I got killed :'(")
|
||||||
|
if ircmsg.find("ERROR :Ping timeout: ") != -1:
|
||||||
|
exit(f"[EXIT][{server} Ping timeout]")
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue