fix: hide cmhub curl download window

This commit is contained in:
chengma
2026-07-08 17:49:54 +08:00
parent 6171b7cd92
commit e25d695ce7
3 changed files with 36 additions and 2 deletions
+16
View File
@@ -1452,6 +1452,21 @@ def _find_system_curl():
return ""
def _subprocess_hidden_window_kwargs():
if os.name != "nt":
return {}
creationflags = getattr(subprocess, "CREATE_NO_WINDOW", 0)
if creationflags:
return {"creationflags": creationflags}
startupinfo_cls = getattr(subprocess, "STARTUPINFO", None)
if startupinfo_cls is None:
return {}
startupinfo = startupinfo_cls()
startupinfo.dwFlags |= getattr(subprocess, "STARTF_USESHOWWINDOW", 1)
startupinfo.wShowWindow = getattr(subprocess, "SW_HIDE", 0)
return {"startupinfo": startupinfo}
def _download_cmhub_image_with_curl(
url,
connect_timeout,
@@ -1501,6 +1516,7 @@ def _download_cmhub_image_with_curl(
timeout=max(2, int(connect_timeout) + int(read_timeout) + 10),
check=False,
shell=False,
**_subprocess_hidden_window_kwargs(),
)
except (OSError, subprocess.TimeoutExpired) as exc:
raise AIError("下载 cmhub 图片失败: curl 执行失败") from exc