fix: prevent browser process leaks and improve robustness
- fix(browser): wrap context lifecycle in try/finally to ensure browser closes on exceptions and KeyboardInterrupt (login, sniffer, generator) - fix(browser): replace time.sleep with Playwright native waits (wait_for, wait_for_timeout) for more reliable element interaction - fix(browser): use parameterized page.evaluate instead of f-string JS injection in generator polling - fix(api): add retry logic in wait_for_completion to survive transient network errors - fix(config): add prepare_profile_dir to copy profile to temp dir, preventing Chromium SingletonLock conflicts when tools run concurrently - fix(sniffer): stream API logs to tempfile instead of unbounded memory list to avoid OOM - fix(api): specify encoding='utf-8' when loading cookies from file Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+11
-2
@@ -190,8 +190,15 @@ class Hunyuan3DAPI:
|
||||
完成的创作信息
|
||||
"""
|
||||
start_time = time.time()
|
||||
last_error = None
|
||||
while time.time() - start_time < timeout:
|
||||
status = self.get_generation_status(creation_id)
|
||||
try:
|
||||
status = self.get_generation_status(creation_id)
|
||||
except Exception as e:
|
||||
last_error = e
|
||||
print(f"查询状态失败: {e},将在 {poll_interval} 秒后重试...")
|
||||
time.sleep(poll_interval)
|
||||
continue
|
||||
|
||||
# Handle both wrapped {code, data} and flat response formats
|
||||
if "code" in status:
|
||||
@@ -209,6 +216,8 @@ class Hunyuan3DAPI:
|
||||
|
||||
time.sleep(poll_interval)
|
||||
|
||||
if last_error:
|
||||
raise TimeoutError(f"Generation timeout after {timeout} seconds. Last error: {last_error}")
|
||||
raise TimeoutError(f"Generation timeout after {timeout} seconds")
|
||||
|
||||
|
||||
@@ -217,7 +226,7 @@ from .config import get_cookie_path
|
||||
def load_cookies_from_file(filepath: Optional[str] = None) -> str:
|
||||
"""从文件加载Cookie,默认读取用户配置目录的 cookies.txt"""
|
||||
path = filepath or str(get_cookie_path())
|
||||
with open(path, 'r') as f:
|
||||
with open(path, 'r', encoding='utf-8') as f:
|
||||
return f.read().strip()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user