From 40a29a8214d853d2af075d8ebaa137f9b6dc2a93 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 24 Feb 2020 17:17:36 +0100 Subject: [PATCH] fire_event could also be called by an external web server or service with no access to the bus. Therefore don't fail hard if the bus is not available --- platypush/event/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/platypush/event/__init__.py b/platypush/event/__init__.py index 7e364850e5..e2f77fc86a 100644 --- a/platypush/event/__init__.py +++ b/platypush/event/__init__.py @@ -1,4 +1,5 @@ import inspect +import logging import threading @@ -9,6 +10,8 @@ class EventGenerator(object): types. Both plugins and backends extend this class. """ + logger = logging.getLogger(__name__) + def __init__(self, *args, **kwargs): self._event_handlers = {} # Event type => callback map @@ -29,7 +32,11 @@ class EventGenerator(object): from platypush.context import get_bus bus = self.bus if isinstance(self, Backend) else get_bus() - bus.post(event) + if not bus: + self.logger.warning('No bus available to post the event: {}'.format(event)) + else: + bus.post(event) + handlers = set() for cls in inspect.getmro(event.__class__):