From 2d2f6ecd8d92309f4c2a468710cd67279e9caa88 Mon Sep 17 00:00:00 2001 From: Cookie987 Date: Tue, 1 Jul 2025 12:50:10 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9D=9ETTY=E7=8E=AF=E5=A2=83=E7=A6=81?= =?UTF-8?q?=E7=94=A8console=5Finput=5Floop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bot.py b/bot.py index 16c264cbb..108a891b1 100644 --- a/bot.py +++ b/bot.py @@ -314,10 +314,16 @@ if __name__ == "__main__": # Schedule tasks returns a future that runs forever. # We can run console_input_loop concurrently. main_tasks = loop.create_task(main_system.schedule_tasks()) - console_task = loop.create_task(console_input_loop(main_system)) - - # Wait for all tasks to complete (which they won't, normally) - loop.run_until_complete(asyncio.gather(main_tasks, console_task)) + # 仅在 TTY 中启用 console_input_loop + if sys.stdin.isatty(): + logger.info("检测到终端环境,启用控制台输入循环") + console_task = loop.create_task(console_input_loop(main_system)) + # Wait for all tasks to complete (which they won't, normally) + loop.run_until_complete(asyncio.gather(main_tasks, console_task)) + else: + logger.info("非终端环境,跳过控制台输入循环") + # Wait for all tasks to complete (which they won't, normally) + loop.run_until_complete(main_tasks) except KeyboardInterrupt: # loop.run_until_complete(get_global_api().stop())