修复退出机制
修复wait_for_user_input()中使用了shutdown_event.wait(),但没有触发set()
This commit is contained in:
10
bot.py
10
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
|
||||
|
||||
Reference in New Issue
Block a user