From 1a22f1678ce38fd5ecaa58726b65ada9e73fda06 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sun, 6 Oct 2013 23:06:59 -0700 Subject: [PATCH] Catching exceptions from listeners in the eventbus to prevent unexpected crashed to crash the core --- homeassistant/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/homeassistant/__init__.py b/homeassistant/__init__.py index 0c183c1f7427..124b7fd44672 100644 --- a/homeassistant/__init__.py +++ b/homeassistant/__init__.py @@ -108,15 +108,17 @@ class EventBus(object): assert isinstance(event, Event), "event needs to be an instance of Event" def run(): - """ We dont want the eventbus to be blocking, - We dont want the eventbus to crash when one of its listeners throws an Exception - So run in a thread. """ + """ We dont want the eventbus to be blocking - run in a thread. """ self.lock.acquire() self.logger.info("EventBus:Event {}: {}".format(event.event_type, event.data)) for callback in chain(self.listeners[ALL_EVENTS], self.listeners[event.event_type]): - callback(event) + try: + callback(event) + + except: + self.logger.exception("EventBus:Exception in listener") if event.remove_listener: if callback in self.listeners[ALL_EVENTS]: