fix(bot): improve code quality by addressing ruff linting warnings
Co-authored-by: Windpicker-owo <221029311+Windpicker-owo@users.noreply.github.com>
This commit is contained in:
8
bot.py
8
bot.py
@@ -610,9 +610,9 @@ async def wait_for_user_input():
|
||||
try:
|
||||
if os.getenv("ENVIRONMENT") != "production":
|
||||
logger.info("程序执行完成,按 Ctrl+C 退出...")
|
||||
# 使用非阻塞循环
|
||||
while True:
|
||||
await asyncio.sleep(0.1)
|
||||
# 使用 asyncio.Event 而不是 sleep 循环
|
||||
shutdown_event = asyncio.Event()
|
||||
await shutdown_event.wait()
|
||||
except KeyboardInterrupt:
|
||||
logger.info("用户中断程序")
|
||||
return True
|
||||
@@ -652,7 +652,7 @@ async def main_async():
|
||||
user_input_done = asyncio.create_task(wait_for_user_input())
|
||||
|
||||
# 使用wait等待任意一个任务完成
|
||||
done, pending = await asyncio.wait([main_task, user_input_done], return_when=asyncio.FIRST_COMPLETED)
|
||||
done, _pending = await asyncio.wait([main_task, user_input_done], return_when=asyncio.FIRST_COMPLETED)
|
||||
|
||||
# 如果用户输入任务完成(用户按了Ctrl+C),取消主任务
|
||||
if user_input_done in done and main_task not in done:
|
||||
|
||||
Reference in New Issue
Block a user