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