diff options
| author | 2019-06-17 11:06:03 +0100 | |
|---|---|---|
| committer | 2019-06-17 11:06:03 +0100 | |
| commit | f8fa529ca5603812d17247e91ca6608a2041bfc2 (patch) | |
| tree | 1b48eb0ed80e86112a8837a52a652ad81d859a44 /src | |
| parent | Allow channel-access and channel-mode check for channels people are not in (diff) | |
| signature | ||
Add IRCBot.panic() - a nicer interface for killing the whole application
Diffstat (limited to 'src')
| -rw-r--r-- | src/IRCBot.py | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/IRCBot.py b/src/IRCBot.py index 243077f3..83f353ca 100644 --- a/src/IRCBot.py +++ b/src/IRCBot.py @@ -1,4 +1,4 @@ -import enum, queue, os, queue, select, socket, threading, time, traceback +import enum, queue, os, queue, select, socket, sys, threading, time, traceback import typing, uuid from src import EventManager, Exports, IRCServer, Logging, ModuleManager from src import Socket, utils @@ -100,6 +100,20 @@ class Bot(object): elif type == TriggerResult.Return: return returned + def panic(self, reason=None): + callback = None + + if not reason == None: + self.log.error("panic() called: %s", [reason]) + + exception = sys.exc_info()[1] + if exception: + def _raise(): + raise exception + callback = _raise + + self._event_queue.put(TriggerEvent(TriggerEventType.Kill, callback)) + def load_modules(self, safe: bool=False ) -> typing.Tuple[typing.List[str], typing.List[str]]: db_blacklist = set(self.get_setting("module-blacklist", [])) @@ -263,6 +277,8 @@ class Bot(object): raise elif item.type == TriggerEventType.Kill: self._kill() + if not item.callback == None: + item.callback() def _post_send_factory(self, server, lines): return lambda: server._post_send(lines) @@ -272,9 +288,8 @@ class Bot(object): def _loop_catch(self, name: str, loop: typing.Callable[[], None]): try: loop() - except: - self.log.critical("Exception on '%s' thread", exc_info=True) - self._event_queue.put(TriggerEvent(TriggerEventType.Kill)) + except Exception as e: + self.panic("Exception on '%s' thread" % name) def _write_loop(self): while self.running: |
