]> jfr.im git - erebus.git/blobdiff - bot.py
fix watchdog, fix exiting when network goes away, etc
[erebus.git] / bot.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()