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