diff options
author | Christoph Zimmermann <monochromec@gmail.com> | 2023-10-29 15:07:30 +0100 |
---|---|---|
committer | Christoph Zimmermann <monochromec@gmail.com> | 2023-10-29 15:07:30 +0100 |
commit | 0ce4092df755748622d05d1104efe7c8fcbaf3f2 (patch) | |
tree | f2a846333462666f83c7d53bde7792117e94c4f4 | |
parent | 335029ce271ff66c444a3aa14027d8943511c6c0 (diff) |
Added check for already loaded module in sys.modules
-rw-r--r-- | glances/stats.py | 29 |
1 files 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 |