From 9492fcde746c41a8da210cf24f3647206e40d879 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Fri, 7 Mar 2025 23:44:07 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=AE=8C=E5=96=84=E4=BA=86=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E5=90=AF=E7=94=A8=E5=92=8C=E7=A6=81=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E7=94=9F=E5=91=BD=E5=91=A8=E6=9C=9F=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/star/star_manager.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/astrbot/core/star/star_manager.py b/astrbot/core/star/star_manager.py index 4c77cf0f..faa45430 100644 --- a/astrbot/core/star/star_manager.py +++ b/astrbot/core/star/star_manager.py @@ -207,10 +207,6 @@ class PluginManager: ) await self._unbind_plugin(smd.name, specified_module_path) - try: - del sys.modules[specified_module_path] - except KeyError: - logger.warning(f"模块 {specified_module_path} 未载入") plugin_modules = self._get_plugin_modules() if plugin_modules is None: @@ -480,6 +476,11 @@ class PluginManager: logger.debug(f"unbind handler {v.handler_name} from {plugin_name} (map)") del star_handlers_registry.star_handlers_map[k] + try: + del sys.modules[plugin_module_path] + except KeyError: + logger.warning(f"模块 {plugin_module_path} 未载入") + async def update_plugin(self, plugin_name: str, proxy=""): """升级一个插件""" plugin = self.context.get_registered_star(plugin_name) @@ -530,6 +531,11 @@ class PluginManager: """终止插件,调用插件的 terminate() 和 __del__() 方法""" logging.info(f"正在终止插件 {star_metadata.name} ...") + if not star_metadata.activated: + # 说明之前已经被禁用了 + logger.debug(f"插件 {star_metadata.name} 未被激活,不需要终止,跳过。") + return + if hasattr(star_metadata.star_cls, "__del__"): asyncio.get_event_loop().run_in_executor( None, star_metadata.star_cls.__del__ @@ -547,12 +553,17 @@ class PluginManager: # 启用插件启用的 llm_tool for func_tool in llm_tools.func_list: - if func_tool.handler_module_path == plugin.module_path: + if ( + func_tool.handler_module_path == plugin.module_path + and func_tool.name in inactivated_llm_tools + ): inactivated_llm_tools.remove(func_tool.name) func_tool.active = True sp.put("inactivated_llm_tools", inactivated_llm_tools) - plugin.activated = True + await self.reload(plugin_name) + + # plugin.activated = True async def install_plugin_from_file(self, zip_file_path: str): dir_name = os.path.basename(zip_file_path).replace(".zip", "")