]> jfr.im git - erebus.git/commitdiff
fix watchdog, fix exiting when network goes away, etc
authorJohn Runyon <redacted>
Sun, 18 Jun 2023 16:50:14 +0000 (10:50 -0600)
committerJohn Runyon <redacted>
Sun, 18 Jun 2023 16:50:14 +0000 (10:50 -0600)
bot.py
erebus.py
modules/control.py

diff --git a/bot.py b/bot.py
index 157b0901dba09cc9f17c4ea9fae0fce143acd199..6ea812815eaadb4d282886a5e0e4fb49baeefbfd 100644 (file)
--- a/bot.py
+++ b/bot.py
@@ -69,7 +69,8 @@ class Bot(object):
        def watchdog(self):
                if time.time() > int(self.parent.cfg.get('watchdog', 'maxtime', default=300))+self.lastreceived:
                        self.parse("ERROR :Fake-error from watchdog timer.")
-               self.watchdogtimer = MyTimer(int(self.parent.cfg.get('watchdog', 'interval', default=30)), self.watchdog)
+               watchdogtimer = MyTimer(int(self.parent.cfg.get('watchdog', 'interval', default=30)), self.watchdog)
+               watchdogtimer.start()
 
        def log(self, *args, **kwargs):
                self.parent.log(self.nick, *args, **kwargs)
@@ -138,6 +139,7 @@ class Bot(object):
                self._checknick()
        def _goterror(self, pieces):
                # TODO: better handling, just reconnect that single bot
+               self.parent.mustquit = Exception(' '.join(pieces))
                try:
                        self.quit("Error detected: %s" % ' '.join(pieces))
                except: pass
@@ -145,7 +147,7 @@ class Bot(object):
                        curs = self.parent.query("UPDATE bots SET connected = 0")
                        curs.close()
                except: pass
-               os._exit(2) # can't use sys.exit since we might be in a sub-thread
+               sys.exit(2)
        def _got001(self, pieces):
                # We wait until the end of MOTD instead to consider ourselves registered, but consider uptime as of 001
                self.connecttime = time.time()
@@ -364,6 +366,7 @@ class Bot(object):
                                                self.msg(user, "Command failed. Code: CBEXC%09.3f" % (time.time() % 100000))
                                                self.__debug_cbexception("hook", user=user, target=target, msg=msg)
                                        except SystemExit as e:
+                                               self.parent.mustquit = e
                                                try:
                                                        curs = self.parent.query("UPDATE bots SET connected = 0")
                                                        curs.close()
index 5893cb8a8a5806d211e45715c00f5c3362ed4a84..4b33231725bdafa149c7bf4e034a12e9c542f24b 100644 (file)
--- a/erebus.py
+++ b/erebus.py
@@ -140,6 +140,7 @@ class Erebus(object): #singleton to pass around
                def __repr__(self): return "<Channel %r>" % (self.name)
 
        def __init__(self, cfg):
+               self.mustquit = None
                self.starttime = time.time()
                self.cfg = cfg
                self.trigger = cfg.trigger
@@ -223,10 +224,12 @@ class Erebus(object): #singleton to pass around
                return chan
 
        def poll(self):
+               timeout_seconds = 30
                if self.potype == "poll":
-                       return [fd for (fd, ev) in self.po.poll()]
+                       pollres = self.po.poll(timeout_seconds * 1000)
+                       return [fd for (fd, ev) in pollres]
                elif self.potype == "select":
-                       return select.select(self.fdlist, [], [])[0]
+                       return select.select(self.fdlist, [], [], timeout_seconds)[0]
 
        def connectall(self):
                for bot in self.bots.values():
@@ -329,6 +332,8 @@ def loop():
        for fileno in poready:
                for line in main.fd(fileno).getdata():
                        main.fd(fileno).parse(line)
+       if main.mustquit is not None:
+               raise main.mustquit
 
 if __name__ == '__main__':
        try: os.rename('logfile', 'oldlogs/%s' % (time.time()))
index b4dbfbf98fce3d3330c787fdb57aaaab377bc461..4d5dbccd20b28b79b9eacc76495647acc507f6dc 100644 (file)
@@ -31,7 +31,6 @@ def die(bot, user, chan, realtarget, *args):
        for botitem in bot.parent.bots.values():
                bot.conn.send("QUIT :Restarting. %s" % (quitmsg))
        sys.exit(0)
-       os._exit(0)
 
 @lib.hook(needchan=False, glevel=lib.MANAGER)
 @lib.help("<mod>", "loads a module")