调整Dota2抖音生图脚本超时为180秒
- 新增脚本级默认超时常量,统一使用 180 秒\n- 修改 --timeout 默认值为 180 秒\n- 调整图片后端 timeout_seconds 的脚本兜底值为 180 秒\n- 补充中文注释,说明超时策略与行为
This commit is contained in:
@@ -44,6 +44,12 @@ DEFAULT_LANGUAGE_VARIANTS = ["zh", "zh", "ja", "ja"]
|
|||||||
# 这里把默认并发数固定为 4,满足你“开 4 个线程跑”的诉求。
|
# 这里把默认并发数固定为 4,满足你“开 4 个线程跑”的诉求。
|
||||||
DEFAULT_MAX_WORKERS = 4
|
DEFAULT_MAX_WORKERS = 4
|
||||||
|
|
||||||
|
# 这里把图片生成默认超时统一收敛到 180 秒:
|
||||||
|
# 1. 300 秒过长时,失败反馈会比较慢,不利于批量任务及时发现问题;
|
||||||
|
# 2. 60 秒又可能不足以覆盖部分高峰期图片生成耗时;
|
||||||
|
# 3. 180 秒作为脚本级默认值,更适合当前这条 Dota2 抖音批量生图链路。
|
||||||
|
DEFAULT_REQUEST_TIMEOUT_SECONDS = 180
|
||||||
|
|
||||||
|
|
||||||
def parse_args() -> argparse.Namespace:
|
def parse_args() -> argparse.Namespace:
|
||||||
"""解析命令行参数。"""
|
"""解析命令行参数。"""
|
||||||
@@ -84,8 +90,8 @@ def parse_args() -> argparse.Namespace:
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--timeout",
|
"--timeout",
|
||||||
type=int,
|
type=int,
|
||||||
default=300,
|
default=DEFAULT_REQUEST_TIMEOUT_SECONDS,
|
||||||
help="单次请求超时时间(秒)。",
|
help="单次请求超时时间(秒),默认 180 秒。",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--delay",
|
"--delay",
|
||||||
@@ -158,7 +164,9 @@ def resolve_image_backend(config_data: Dict[str, Any], scene_name: str) -> Dict[
|
|||||||
"api_key": str(backend_config.get("api_key") or "").strip(),
|
"api_key": str(backend_config.get("api_key") or "").strip(),
|
||||||
"model": str(backend_config.get("model") or "gpt-image-1").strip(),
|
"model": str(backend_config.get("model") or "gpt-image-1").strip(),
|
||||||
"endpoint": "images/generations",
|
"endpoint": "images/generations",
|
||||||
"timeout_seconds": int(backend_config.get("timeout_seconds") or 300),
|
# 这里给脚本自己的后端超时兜底值也同步改成 180 秒,
|
||||||
|
# 避免配置文件里没写 timeout_seconds 时又悄悄回退到旧的 300 秒。
|
||||||
|
"timeout_seconds": int(backend_config.get("timeout_seconds") or DEFAULT_REQUEST_TIMEOUT_SECONDS),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -531,7 +539,10 @@ def main() -> int:
|
|||||||
|
|
||||||
manifest_path = output_dir / "generation_manifest.jsonl"
|
manifest_path = output_dir / "generation_manifest.jsonl"
|
||||||
request_url = build_request_url(backend["api_base_url"], backend["endpoint"])
|
request_url = build_request_url(backend["api_base_url"], backend["endpoint"])
|
||||||
timeout_seconds = args.timeout or backend["timeout_seconds"]
|
# 这里优先使用命令行显式传入的超时值;
|
||||||
|
# 若用户未额外指定,则沿用 argparse 默认值 180 秒。
|
||||||
|
# 这样这个脚本的行为是稳定可预期的,不会再因为历史默认值导致请求挂太久。
|
||||||
|
timeout_seconds = int(args.timeout or backend["timeout_seconds"])
|
||||||
|
|
||||||
heroes = fetch_dota2_heroes()
|
heroes = fetch_dota2_heroes()
|
||||||
if args.hero_filter:
|
if args.hero_filter:
|
||||||
|
|||||||
Reference in New Issue
Block a user