使用同步处理机制

This commit is contained in:
liuwei
2025-05-16 09:58:34 +08:00
parent 11a3c4ef6b
commit 1a0220a907
2 changed files with 6 additions and 8 deletions

View File

@@ -220,12 +220,13 @@ class Robot(Job):
self.LOG.error(f"获取新消息失败 {e}")
if e == "用户可能退出":
self.LOG.error(f"获取新消息失败 {e},请重启应用重新登录!")
self.ipad_running = False
# self.ipad_running = False
await asyncio.sleep(5)
continue
data = data.get("AddMsgs")
if data:
tasks = []
for message in data:
self.LOG.debug(f"sync_message.处理消息消息内容: {message}")
# 处理消息
@@ -234,12 +235,9 @@ class Robot(Job):
except Exception as e:
self.LOG.error(f"WxMessage.from_json 解析失败,消息内容: {message},错误: {e}")
continue # 跳过本条消息,继续处理下一条
try:
await self._process_ipad_message(wxmsg)
except Exception as e:
self.LOG.error(f"捕获消息处理异常,继续进行下一个消息处理{e}")
continue
tasks.append(self._process_ipad_message(wxmsg))
if tasks:
await asyncio.gather(*tasks)
# 使用异步睡眠替代忙等待循环
await asyncio.sleep(0.5)

View File

@@ -5,7 +5,7 @@ import asyncio
# linux 下需要安装字体
# sudo apt-get install -y fonts-noto-cjk fonts-noto-cjk-extra
# sudo apt-get install -y fonts-noto-color-emoji fonts-noto-cjk fonts-wqy-microhei
# 将 Markdown 字符串转换为 HTML
def md_str_to_html(md_content, output_html):
"""