Prevent the plugin from being initialized again within the lock scope if another thread had it initialized in the meantime

This commit is contained in:
Fabio Manganiello 2018-09-18 19:19:41 +02:00
parent 98d24b061a
commit db5d3e6e3f

View file

@ -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():