mirror of
https://github.com/nicolargo/glances.git
synced 2024-12-23 09:11:49 +03:00
Added check for already loaded module in sys.modules
This commit is contained in:
parent
335029ce27
commit
0ce4092df7
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user