From cb9c5834df17bd2535a645de5acf342750e299f8 Mon Sep 17 00:00:00 2001 From: HibiKier <775757368@qq.com> Date: Tue, 23 Dec 2025 17:07:36 +0800 Subject: [PATCH] chore: cancel only zhenxun tasks on shutdown --- zhenxun/services/__init__.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/zhenxun/services/__init__.py b/zhenxun/services/__init__.py index b02a5e39..209cc2ec 100644 --- a/zhenxun/services/__init__.py +++ b/zhenxun/services/__init__.py @@ -94,14 +94,18 @@ __all__ = [ async def cancel_pending_tasks(): - """在关闭前尽量取消仍在运行的协程,避免关闭后继续访问数据库连接池。""" + """仅取消 zhenxun 业务协程,避免干扰框架的关机流程。""" loop = asyncio.get_running_loop() current = asyncio.current_task(loop=loop) - pending = [ - task - for task in asyncio.all_tasks(loop) - if task is not current and not task.done() - ] + pending = [] + for task in asyncio.all_tasks(loop): + if task is current or task.done(): + continue + coro = task.get_coro() + module = getattr(coro, "__module__", "") + if module.startswith("zhenxun"): + pending.append(task) + if not pending: return