From bbc43f8972bafdd65bf2ee6a28e4f77ee32cb4bd Mon Sep 17 00:00:00 2001 From: Zichao Lin Date: Sun, 12 Jul 2026 23:51:45 +0800 Subject: [PATCH] fix: keep pending_uids until TG send completes to prevent duplicate processing --- main.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 114242f..e2f3af4 100644 --- a/main.py +++ b/main.py @@ -87,7 +87,7 @@ def _ai_processor(cfg): _tg_queue.put(info) except Exception as e: logger.error(f"AI 处理邮件失败: {e}", exc_info=True) - finally: + # AI 失败也要移除 pending,否则永远卡住 with _pending_lock: _pending_uids.discard(mail.uid) @@ -107,10 +107,19 @@ def _tg_worker(cfg): try: info = _tg_queue.get_nowait() tg_send_and_mark(cfg, info) + # 发送并标记已读成功后才移除 pending + with _pending_lock: + _pending_uids.discard(info["uid"]) except queue_module.Empty: break except Exception as e: logger.error(f"TG 发送失败: {e}", exc_info=True) + # 发送失败也要移除 pending,避免永久阻塞 + try: + with _pending_lock: + _pending_uids.discard(info["uid"]) + except Exception: + pass if _running: time.sleep(1)