From bea0d033cf8ac50adf2c3d6c043d3f5569e20f8a Mon Sep 17 00:00:00 2001 From: LuiKlee Date: Thu, 27 Nov 2025 19:21:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=80=80=E5=87=BA=E6=9C=BA?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复wait_for_user_input()中使用了shutdown_event.wait(),但没有触发set() --- bot.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bot.py b/bot.py index 9dc5e509b..4cdb54ede 100644 --- a/bot.py +++ b/bot.py @@ -249,7 +249,7 @@ class ShutdownManager: return success except Exception as e: - logger.error(f"麦麦关闭失败: {e}") + logger.error(f"麦麦关闭失败: {e}", exc_info=True) return False @@ -602,12 +602,11 @@ class MaiBotMain: async def wait_for_user_input(): """等待用户输入(异步方式)""" try: - # 在非生产环境下,使用异步方式等待输入 if os.getenv("ENVIRONMENT") != "production": logger.info("程序执行完成,按 Ctrl+C 退出...") - # 使用 Event 替代 sleep 循环,避免阻塞事件循环 - shutdown_event = asyncio.Event() - await shutdown_event.wait() + # 使用非阻塞循环 + while True: + await asyncio.sleep(0.1) except KeyboardInterrupt: logger.info("用户中断程序") return True @@ -616,6 +615,7 @@ async def wait_for_user_input(): return False + async def main_async(): """主异步函数""" exit_code = 0