From db5d3e6e3fbcff44896893ea79dfe5a029419565 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 18 Sep 2018 19:19:41 +0200 Subject: [PATCH] Prevent the plugin from being initialized again within the lock scope if another thread had it initialized in the meantime --- platypush/context/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/platypush/context/__init__.py b/platypush/context/__init__.py index 4f7ffccd0..95945b589 100644 --- a/platypush/context/__init__.py +++ b/platypush/context/__init__.py @@ -94,13 +94,15 @@ def get_plugin(plugin_name, reload=False): try: plugin_class = getattr(plugin, cls_name) - - with plugins_init_locks[plugin_name]: - plugins[plugin_name] = plugin_class(**plugin_conf) except AttributeError as e: logger.warning('No such class in {}: {}'.format(plugin_name, cls_name)) raise RuntimeError(e) + with plugins_init_locks[plugin_name]: + if plugins.get(plugin_name) and not reload: + return plugins[plugin_name] + plugins[plugin_name] = plugin_class(**plugin_conf) + return plugins[plugin_name] def get_bus():