From 1b7e4fbbdc732a26113bfc7a997dcbfcb59215e4 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Wed, 8 Jan 2025 12:43:34 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E9=80=80=E5=87=BA=E6=97=B6=E5=85=B3?= =?UTF-8?q?=E9=97=AD=20aiohttp=20client=20session?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/core_lifecycle.py | 2 ++ astrbot/core/provider/manager.py | 7 ++++++- astrbot/core/provider/sources/dify_source.py | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/astrbot/core/core_lifecycle.py b/astrbot/core/core_lifecycle.py index 3655e55ee..ddb285cc9 100644 --- a/astrbot/core/core_lifecycle.py +++ b/astrbot/core/core_lifecycle.py @@ -92,6 +92,8 @@ class AstrBotCoreLifecycle: self.event_queue.closed = True for task in self.curr_tasks: task.cancel() + + await self.provider_manager.terminate() for task in self.curr_tasks: try: diff --git a/astrbot/core/provider/manager.py b/astrbot/core/provider/manager.py index 20ac8a0d0..ea90470db 100644 --- a/astrbot/core/provider/manager.py +++ b/astrbot/core/provider/manager.py @@ -65,4 +65,9 @@ class ProviderManager(): logger.warning("未启用任何大模型提供商适配器。") def get_insts(self): - return self.provider_insts \ No newline at end of file + return self.provider_insts + + async def terminate(self): + for provider_inst in self.provider_insts: + if hasattr(provider_inst, "terminate"): + await provider_inst.terminate() \ No newline at end of file diff --git a/astrbot/core/provider/sources/dify_source.py b/astrbot/core/provider/sources/dify_source.py index 64755c968..4ee1897e6 100644 --- a/astrbot/core/provider/sources/dify_source.py +++ b/astrbot/core/provider/sources/dify_source.py @@ -127,3 +127,6 @@ class ProviderDify(Provider): async def get_human_readable_context(self, session_id, page, page_size): raise Exception("暂不支持获得 Dify 的历史消息记录。") + + async def terminate(self): + await self.api_client.close() \ No newline at end of file