fix:normal出现未正常进行的一步操作

This commit is contained in:
SengokuCola
2025-07-08 00:27:33 +08:00
parent 3c46d996fe
commit 08ae2e83e3
2 changed files with 34 additions and 43 deletions

View File

@@ -302,9 +302,11 @@ class NormalChat:
logger.info(f"[{self.stream_name}] 在处理上下文中检测到停止信号,退出")
break
# 并行处理兴趣消息
async def process_single_message(msg_id, message, interest_value, is_mentioned):
"""处理单个兴趣消息"""
semaphore = asyncio.Semaphore(5)
async def process_and_acquire(msg_id, message, interest_value, is_mentioned):
"""处理单个兴趣消息并管理信号量"""
async with semaphore:
try:
# 在处理每个消息前检查停止状态
if self._disabled:
@@ -329,23 +331,13 @@ class NormalChat:
# 无论如何都要清理消息
self.interest_dict.pop(msg_id, None)
# 创建并行任务列表
coroutines = []
for msg_id, (message, interest_value, is_mentioned) in items_to_process:
coroutine = process_single_message(msg_id, message, interest_value, is_mentioned)
coroutines.append(coroutine)
tasks = [
process_and_acquire(msg_id, message, interest_value, is_mentioned)
for msg_id, (message, interest_value, is_mentioned) in items_to_process
]
# 并行执行所有任务,限制并发数量避免资源过度消耗
if coroutines:
# 使用信号量控制并发数最多同时处理5个消息
semaphore = asyncio.Semaphore(5)
async def limited_process(coroutine, sem):
async with sem:
await coroutine
limited_tasks = [limited_process(coroutine, semaphore) for coroutine in coroutines]
await asyncio.gather(*limited_tasks, return_exceptions=True)
if tasks:
await asyncio.gather(*tasks, return_exceptions=True)
except asyncio.CancelledError:
logger.info(f"[{self.stream_name}] 处理上下文时任务被取消")

View File

@@ -355,14 +355,13 @@ class NoReplyAction(BaseAction):
last_judge_time = time.time() # 异常时也更新时间,避免频繁重试
# 每10秒输出一次等待状态
logger.info(f"{self.log_prefix} 开始等待新消息...")
if elapsed_time < 60:
if int(elapsed_time) % 10 == 0 and int(elapsed_time) > 0:
logger.debug(f"{self.log_prefix} 已等待{elapsed_time:.0f}秒,等待新消息...")
await asyncio.sleep(1)
else:
if int(elapsed_time) % 60 == 0 and int(elapsed_time) > 0:
logger.debug(f"{self.log_prefix} 已等待{elapsed_time / 60:.0f}分钟,等待新消息...")
if int(elapsed_time) % 180 == 0 and int(elapsed_time) > 0:
logger.info(f"{self.log_prefix} 已等待{elapsed_time / 60:.0f}分钟,等待新消息...")
await asyncio.sleep(1)
# 短暂等待后继续检查