diff --git a/platypush/__init__.py b/platypush/__init__.py index e5aa2b117..d03513efe 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 5dd497501..86195b9ca 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):