From 54b0a0aed741bfd5b91c47005e029b25f6768f97 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sun, 14 Aug 2016 19:40:42 +0100 Subject: [PATCH] Gracefully handle callback crashes. --- econtext/core.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/econtext/core.py b/econtext/core.py index 81ffc942..e7d190d3 100644 --- a/econtext/core.py +++ b/econtext/core.py @@ -329,7 +329,7 @@ class Stream(BasicStream): return True def _invoke(self, handle, data): - IOLOG.debug('%r._invoke(): handle=%r; data=%r', self, handle, data) + IOLOG.debug('%r._invoke(%r, %r)', self, handle, data) try: persist, fn = self._context._handle_map[handle] except KeyError: @@ -337,7 +337,11 @@ class Stream(BasicStream): if not persist: del self._context._handle_map[handle] - fn(data) + + try: + fn(data) + except Exception: + LOG.debug('%r._invoke(%r, %r): %r crashed', self, handle, data, fn) def on_transmit(self): """Transmit buffered messages."""