增强登录稳定性

This commit is contained in:
yml2213
2026-06-24 09:17:15 +08:00
parent 177ec42416
commit 7bb50a9bbf
4 changed files with 106 additions and 14 deletions
+11 -1
View File
@@ -2,6 +2,7 @@
import html
import re
import threading
import time
from datetime import datetime, timedelta
from typing import Optional
@@ -261,6 +262,7 @@ class EmailVerifier:
interval: int = 3,
after_timestamp: Optional[float] = None,
allow_old_seconds: int = 15,
stop_event: Optional[threading.Event] = None,
) -> str:
"""
轮询获取斗鱼验证码。优先使用 Roundcube API,失败则回退到 read.php。
@@ -270,6 +272,7 @@ class EmailVerifier:
interval: 轮询间隔(秒)
after_timestamp: 发送验证码请求的时间戳,用于过滤旧邮件
allow_old_seconds: 允许的时间偏移(秒)
stop_event: 外部停止信号,触发后尽快中断等待
Returns:
6位验证码
@@ -281,6 +284,9 @@ class EmailVerifier:
tried_roundcube = False
while time.monotonic() < deadline:
if stop_event and stop_event.is_set():
raise InterruptedError("任务已停止")
# 优先尝试 Roundcube
if not tried_roundcube or self._rc_logged_in:
try:
@@ -304,7 +310,11 @@ class EmailVerifier:
logger.warning(f"read.php 读邮件异常: {e}")
logger.debug("未找到验证码,等待中...")
time.sleep(interval)
sleep_deadline = time.monotonic() + interval
while time.monotonic() < sleep_deadline:
if stop_event and stop_event.is_set():
raise InterruptedError("任务已停止")
time.sleep(min(0.2, sleep_deadline - time.monotonic()))
raise TimeoutError(f"等待验证码超时{'' + last_error + '' if last_error else ''}")