CRITICAL log exceptions caught in _loop_catch()

This commit is contained in:
jesopo 2019-06-15 00:39:52 +01:00
parent 04f3e98515
commit b5a467552f

View file

@ -238,9 +238,9 @@ class Bot(object):
def run(self): def run(self):
self._read_thread = self._daemon_thread( self._read_thread = self._daemon_thread(
lambda: self._loop_catch(self._read_loop)) lambda: self._loop_catch("read", self._read_loop))
self._write_thread = self._daemon_thread( self._write_thread = self._daemon_thread(
lambda: self._loop_catch(self._write_loop)) lambda: self._loop_catch("write", self._write_loop))
self._event_loop() self._event_loop()
def _kill(self): def _kill(self):
@ -269,12 +269,12 @@ class Bot(object):
def _post_read_factory(self, server, lines): def _post_read_factory(self, server, lines):
return lambda: server._post_read(lines) return lambda: server._post_read(lines)
def _loop_catch(self, loop: typing.Callable[[], None]): def _loop_catch(self, name: str, loop: typing.Callable[[], None]):
try: try:
loop() loop()
except: except:
self.log.critical("Exception on '%s' thread", exc_info=True)
self._event_queue.put(TriggerEvent(TriggerEventType.Kill)) self._event_queue.put(TriggerEvent(TriggerEventType.Kill))
raise
def _write_loop(self): def _write_loop(self):
while self.running: while self.running: