Added check for already loaded module in sys.modules

This commit is contained in:
Christoph Zimmermann 2023-10-29 15:07:30 +01:00
parent 335029ce27
commit 0ce4092df7

View File

@ -164,19 +164,22 @@ class GlancesStats(object):
# Ensure that plugins can be found in plugin_dir
sys.path.insert(0, path)
for plugin in get_addl_plugins(self, path):
start_duration.reset()
try:
_mod_loaded = import_module(plugin+'.model')
self._plugins[plugin] = _mod_loaded.PluginModel(args=args, config=config)
logger.debug("Plugin {} started in {} seconds".format(plugin, start_duration.get()))
except Exception as e:
# If a plugin can not be loaded, display a critical message
# on the console but do not crash
logger.critical("Error while initializing the {} plugin ({})".format(plugin, e))
logger.error(traceback.format_exc())
# An error occurred, disable the plugin
if args:
setattr(args, 'disable_' + plugin, False)
if plugin in sys.modules:
logger.warn(f"Pugin {plugin} already in sys.modules, skipping (workaround: rename plugin)")
else:
start_duration.reset()
try:
_mod_loaded = import_module(plugin+'.model')
self._plugins[plugin] = _mod_loaded.PluginModel(args=args, config=config)
logger.debug("Plugin {} started in {} seconds".format(plugin, start_duration.get()))
except Exception as e:
# If a plugin can not be loaded, display a critical message
# on the console but do not crash
logger.critical("Error while initializing the {} plugin ({})".format(plugin, e))
logger.error(traceback.format_exc())
# An error occurred, disable the plugin
if args:
setattr(args, 'disable_' + plugin, False)
sys.path = _sys_path
# Log plugins list