From ce2032b932affebf9dbde5303f85f76648582203 Mon Sep 17 00:00:00 2001 From: liuwei Date: Wed, 19 Mar 2025 10:22:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=8F=92=E4=BB=B6=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin_common/plugin_manager.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/plugin_common/plugin_manager.py b/plugin_common/plugin_manager.py index 1875040..a1803f6 100644 --- a/plugin_common/plugin_manager.py +++ b/plugin_common/plugin_manager.py @@ -313,3 +313,29 @@ class PluginManager: # 加载插件 return self.load_plugin(plugin_name) + + def shutdown_plugins(self) -> bool: + """ + 卸载所有插件 + + Returns: + 是否全部成功卸载 + """ + success = True + # 创建插件名称的副本,因为在卸载过程中会修改self.plugins字典 + plugin_names = list(self.plugins.keys()) + + for plugin_name in plugin_names: + if not self.unload_plugin(plugin_name): + self.LOG.error(f"卸载插件 {plugin_name} 失败") + success = False + + # 清空插件模块字典 + self.plugin_modules.clear() + + # 确保插件字典为空 + if self.plugins: + self.LOG.warning(f"插件卸载后仍有 {len(self.plugins)} 个插件残留") + success = False + + return success