From 331102560d0c57907d6498fa885e11aed1189eed Mon Sep 17 00:00:00 2001 From: KimigaiiWuyi <444835641@qq.com> Date: Mon, 19 May 2025 13:12:04 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E5=AF=BC?= =?UTF-8?q?=E5=85=A5Bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gsuid_core/server.py | 13 +++++++++++-- gsuid_core/web_app.py | 6 ++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/gsuid_core/server.py b/gsuid_core/server.py index e7c92b2..f9bd6d5 100644 --- a/gsuid_core/server.py +++ b/gsuid_core/server.py @@ -1,4 +1,3 @@ -import os import re import sys import time @@ -8,7 +7,6 @@ import subprocess import importlib.util from pathlib import Path from types import ModuleType -from concurrent.futures import ThreadPoolExecutor from typing import Dict, List, Tuple, Union, Callable import toml @@ -214,6 +212,16 @@ class GsServer: continue all_plugins.extend(d) + for module_name, filepath, _type in all_plugins: + try: + self.cached_import(module_name, filepath, _type) + except Exception as e: + logger.exception( + f'❌ 插件{filepath.stem}导入失败, 错误代码: {e}' + ) + continue + + ''' max_workers = min(12, (os.cpu_count() or 1) * 2) with ThreadPoolExecutor(max_workers=max_workers) as executor: _ = { @@ -222,6 +230,7 @@ class GsServer: ): module_name for module_name, filepath, _type in all_plugins } + ''' core_config.lazy_write_config() logger.success('[GsCore] 插件加载完成!') diff --git a/gsuid_core/web_app.py b/gsuid_core/web_app.py index 5bdcba0..edd3480 100644 --- a/gsuid_core/web_app.py +++ b/gsuid_core/web_app.py @@ -58,14 +58,12 @@ async def lifespan(app: FastAPI): '[GsCore] 执行启动Hook函数中!', [_def.__name__ for _def in core_start_def], ) - ctask = [] for _def in core_start_def: if asyncio.iscoroutinefunction(_def): asyncio.create_task(_def()) else: - ctask.append(asyncio.to_thread(_def)) - if ctask: - await asyncio.gather(*ctask) + asyncio.create_task(asyncio.to_thread(_def)) + except Exception as e: logger.exception(e)