diff --git a/main.py b/main.py index 4965b1c..12a2484 100644 --- a/main.py +++ b/main.py @@ -107,24 +107,24 @@ def _tg_worker(cfg): except Exception as e: logger.error(f"TG 轮询错误: {e}", exc_info=True) - while _running: + # 每轮只处理一封待发邮件,然后立刻回去 poll Telegram + try: + info = _tg_queue.get_nowait() + tg_send_and_mark(cfg, info) + uid_str = info["uid"].decode("utf-8", errors="replace") if isinstance(info["uid"], bytes) else str(info["uid"]) + mark_sent(uid_str) + except queue_module.Empty: + pass + except Exception as e: + logger.error(f"TG 发送失败: {e}", exc_info=True) try: - info = _tg_queue.get_nowait() - tg_send_and_mark(cfg, info) uid_str = info["uid"].decode("utf-8", errors="replace") if isinstance(info["uid"], bytes) else str(info["uid"]) - mark_sent(uid_str) - except queue_module.Empty: - break - except Exception as e: - logger.error(f"TG 发送失败: {e}", exc_info=True) - try: - uid_str = info["uid"].decode("utf-8", errors="replace") if isinstance(info["uid"], bytes) else str(info["uid"]) - mark_failed(uid_str) - except Exception: - pass + mark_failed(uid_str) + except Exception: + pass if _running: - _shutdown_event.wait(1) + _shutdown_event.wait(0.2) def main():