fix:ai哥神秘修复无法模式切换

This commit is contained in:
SengokuCola
2025-06-15 01:27:54 +08:00
parent 4b7dae41e5
commit 327580dbec
6 changed files with 197 additions and 75 deletions

31
bot.py
View File

@@ -109,12 +109,33 @@ async def graceful_shutdown():
# 停止所有异步任务
await async_task_manager.stop_and_wait_all_tasks()
tasks = [t for t in asyncio.all_tasks() if t is not asyncio.current_task()]
for task in tasks:
task.cancel()
await asyncio.gather(*tasks, return_exceptions=True)
# 获取所有剩余任务,排除当前任务
remaining_tasks = [t for t in asyncio.all_tasks() if t is not asyncio.current_task()]
if remaining_tasks:
logger.info(f"正在取消 {len(remaining_tasks)} 个剩余任务...")
# 取消所有剩余任务
for task in remaining_tasks:
if not task.done():
task.cancel()
# 等待所有任务完成,设置超时
try:
await asyncio.wait_for(
asyncio.gather(*remaining_tasks, return_exceptions=True),
timeout=15.0
)
logger.info("所有剩余任务已成功取消")
except asyncio.TimeoutError:
logger.warning("等待任务取消超时,强制继续关闭")
except Exception as e:
logger.error(f"等待任务取消时发生异常: {e}")
logger.info("麦麦优雅关闭完成")
except Exception as e:
logger.error(f"麦麦关闭失败: {e}")
logger.error(f"麦麦关闭失败: {e}", exc_info=True)
def check_eula():