🤖 自动格式化代码 [skip ci]
This commit is contained in:
@@ -335,8 +335,6 @@ async def clean_unused_emojis(emoji_dir: str, emoji_objects: List["MaiEmoji"], r
|
||||
for file_name in os.listdir(emoji_dir):
|
||||
file_full_path = os.path.join(emoji_dir, file_name)
|
||||
|
||||
|
||||
|
||||
# 确保处理的是文件而不是子目录
|
||||
if not os.path.isfile(file_full_path):
|
||||
continue
|
||||
|
||||
@@ -298,7 +298,9 @@ class HeartFChatting:
|
||||
|
||||
# 使用异步上下文管理器处理消息
|
||||
try:
|
||||
async with global_prompt_manager.async_message_scope(self.chat_stream.context.get_template_name()):
|
||||
async with global_prompt_manager.async_message_scope(
|
||||
self.chat_stream.context.get_template_name()
|
||||
):
|
||||
# 在上下文内部检查关闭状态
|
||||
if self._shutting_down:
|
||||
logger.info(f"{self.log_prefix} 在处理上下文中检测到关闭信号,退出")
|
||||
@@ -357,7 +359,9 @@ class HeartFChatting:
|
||||
timer_strings.append(f"{name}: {formatted_time}")
|
||||
|
||||
# 新增:输出每个处理器的耗时
|
||||
processor_time_costs = self._current_cycle_detail.loop_processor_info.get("processor_time_costs", {})
|
||||
processor_time_costs = self._current_cycle_detail.loop_processor_info.get(
|
||||
"processor_time_costs", {}
|
||||
)
|
||||
processor_time_strings = []
|
||||
for pname, ptime in processor_time_costs.items():
|
||||
formatted_ptime = f"{ptime * 1000:.2f}毫秒" if ptime < 1 else f"{ptime:.2f}秒"
|
||||
|
||||
@@ -196,7 +196,9 @@ class NormalChat:
|
||||
|
||||
# 使用异步上下文管理器处理消息
|
||||
try:
|
||||
async with global_prompt_manager.async_message_scope(self.chat_stream.context.get_template_name()):
|
||||
async with global_prompt_manager.async_message_scope(
|
||||
self.chat_stream.context.get_template_name()
|
||||
):
|
||||
# 在上下文内部再次检查取消状态
|
||||
if self._disabled:
|
||||
logger.info(f"[{self.stream_name}] 在处理上下文中检测到停止信号,退出")
|
||||
|
||||
@@ -4,12 +4,12 @@ NormalChat 启动停止测试脚本
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import time
|
||||
import logging
|
||||
from src.common.logger import get_logger
|
||||
|
||||
logger = get_logger("test_normal_chat_stop")
|
||||
|
||||
|
||||
async def test_task_cancel_behavior():
|
||||
"""测试任务取消行为"""
|
||||
|
||||
@@ -85,6 +85,7 @@ async def test_task_cancel_behavior():
|
||||
|
||||
logger.info("=== 测试完成 ===")
|
||||
|
||||
|
||||
async def main():
|
||||
"""主函数"""
|
||||
logger.info("开始 NormalChat 停止测试")
|
||||
@@ -94,10 +95,12 @@ async def main():
|
||||
except Exception as e:
|
||||
logger.error(f"测试失败: {e}")
|
||||
import traceback
|
||||
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
logger.info("测试结束")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 设置日志级别
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
Reference in New Issue
Block a user