From cb423dab03348dc498a3bf7474f5b5f2dcfbbaf2 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sat, 16 Dec 2017 07:01:25 +0100 Subject: [PATCH] Removed short circuit on the response --- platypush/__init__.py | 13 +++++++------ platypush/backend/__init__.py | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/platypush/__init__.py b/platypush/__init__.py index e5aa2b11..d03513ef 100644 --- a/platypush/__init__.py +++ b/platypush/__init__.py @@ -57,7 +57,8 @@ def _init_plugin(plugin_name, reload=False): return plugin -def _exec_func(args, backend=None, retry=True): +def _exec_func(args, retry=True): + backend = args.pop('backend') if 'backend' in args else None origin = args.pop('origin') if 'origin' in args else None action = args.pop('action') tokens = action.split('.') @@ -81,17 +82,17 @@ def _exec_func(args, backend=None, retry=True): logging.exception(e) if retry: # Put the popped args back where they were before retrying - args['action'] = action; args['origin'] = origin + args['action'] = action; args['origin'] = origin; args['backend'] = backend logging.info('Reloading plugin {} and retrying'.format(module_name)) _init_plugin(module_name, reload=True) - _exec_func(args, backend, retry=False) + _exec_func(args, retry=False) finally: if backend: backend.send_response(origin, response) -def on_msg(msg, backend=None): - Thread(target=_exec_func, args=(msg,backend)).start() +def on_msg(msg): + Thread(target=_exec_func, args=(msg,)).start() def parse_config_file(config_file=None): @@ -216,7 +217,7 @@ Usage: {} [-v] [-h] [-c ] while True: try: - on_msg(mq.get(), backend) + on_msg(mq.get()) except KeyboardInterrupt: return diff --git a/platypush/backend/__init__.py b/platypush/backend/__init__.py index 5dd49750..86195b9c 100644 --- a/platypush/backend/__init__.py +++ b/platypush/backend/__init__.py @@ -62,6 +62,7 @@ class Backend(Thread): self.on_error('No action specified: {}'.format(msg)) return + msg['backend'] = self # Augment message self.mq.put(msg) def send_msg(self, msg): @@ -72,7 +73,6 @@ class Backend(Thread): 'a dictionary but received {}'.format(type(msg))) msg['origin'] = self.device_id # To get the response - self._send_msg(msg) def send_response(self, target, response):