From 280b59a662d3fbe7bc715f9364709dc464e3bd9e Mon Sep 17 00:00:00 2001 From: liuwei Date: Fri, 30 May 2025 09:20:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=BA=BF=E7=A8=8B=E5=8F=91?= =?UTF-8?q?=E9=80=81=E3=80=82=E9=98=B2=E6=AD=A2=E9=98=BB=E5=A1=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/dashboard/blueprints/contacts.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/admin/dashboard/blueprints/contacts.py b/admin/dashboard/blueprints/contacts.py index 88f4ec6..5298853 100644 --- a/admin/dashboard/blueprints/contacts.py +++ b/admin/dashboard/blueprints/contacts.py @@ -16,8 +16,25 @@ def send_message_in_thread(func, *args, **kwargs): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) - # 运行异步函数 - loop.run_until_complete(func(*args, **kwargs)) + # 创建异步任务 + async def send(): + try: + await func(*args, **kwargs) + finally: + # 发送完成后停止事件循环 + loop.stop() + + # 创建任务 + task = asyncio.create_task(send()) + + # 运行事件循环直到停止 + loop.run_forever() + + # 等待任务完成 + if not task.done(): + task.cancel() + loop.run_until_complete(task) + except Exception as e: logger.error(f"发送消息失败: {e}") finally: