fix logger

This commit is contained in:
CakeCN
2025-12-11 15:23:50 +08:00
parent 99758ce1f8
commit 5df2931fa1

View File

@@ -433,20 +433,31 @@ class HSAEngineClient(ASEngineClient):
super().__init__(server_url, namespace, id)
self.chatmanager = chatmanager
def loadmarkdown(self, fmd, fmdp, fsp):
with self.chatmanager.app.app_context():
# 保存app实例以便在回调中使用
app = self.chatmanager.app
def log_info(message):
"""安全的日志记录函数,确保在任何线程中都能使用"""
try:
with app.app_context():
app.logger.info(message)
except Exception as e:
print(f"Log error: {e}")
print(f"Message: {message}")
now = time.time()
# 并行发送三个消息获取事件对象和ack_id
event1, ack_id1 = self.send_text('markdown-in', fmd, self.id, wait_for_ack=True, return_event=True)
event2, ack_id2 = self.send_text('markdown-prompt-in', fmdp, self.id, wait_for_ack=True, return_event=True)
event3, ack_id3 = self.send_text('score-prompt-in', fsp, self.id, wait_for_ack=True, return_event=True)
self.chatmanager.app.logger.info(f"Load markdown time cost: {time.time() - now}")
log_info(f"Load markdown time cost: {time.time() - now}")
now = time.time()
# 等待所有事件完成
timeout = 5 # 超时时间
success1 = event1.wait(timeout=timeout)
success2 = event2.wait(timeout=timeout)
success3 = event3.wait(timeout=timeout)
self.chatmanager.app.logger.info(f"Wait markdown time cost: {time.time() - now}")
log_info(f"Wait markdown time cost: {time.time() - now}")
now = time.time()
# 清理ACK事件
if ack_id1 in self.ack_events: