From 0ce4092df755748622d05d1104efe7c8fcbaf3f2 Mon Sep 17 00:00:00 2001 From: Christoph Zimmermann Date: Sun, 29 Oct 2023 15:07:30 +0100 Subject: Added check for already loaded module in sys.modules --- glances/stats.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/glances/stats.py b/glances/stats.py index 803914f3..67688127 100644 --- a/glances/stats.py +++ b/glances/stats.py @@ -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 -- cgit v1.2.3