ATH-MaaS/Pixelle-Video · error · TimeoutError

可灵视频生成超时 (task_id={task_id}, 已等待 {self.max_polls * self.poll

Error message

可灵视频生成超时 (task_id={task_id}, 已等待 {self.max_polls * self.poll_interval}s)

What it means

_poll_until_done polled max_polls times without the task reaching 'succeed' or 'failed'; the task is still submitted/processing. It raises TimeoutError reporting the total wait (max_polls * poll_interval) so the caller can decide to give up or re-check later.

Source

Thrown at pixelle_video/services/api_services/video_kling.py:322

        for attempt in range(self.max_polls):
            result = self._query_task(task_id, endpoint=endpoint)
            status = result.get("task_status", "")

            if status == "succeed":
                logger.info(f"KlingVideoClient: 任务完成 task_id={task_id}")
                return result
            elif status == "failed":
                msg = result.get("task_status_msg", "未知错误")
                raise RuntimeError(f"可灵视频生成失败: {msg} (task_id={task_id})")
            else:
                # submitted / processing
                logger.debug(
                    f"KlingVideoClient: 任务进行中 task_id={task_id}, "
                    f"status={status}, attempt={attempt + 1}/{self.max_polls}"
                )
                time.sleep(self.poll_interval)

        raise TimeoutError(f"可灵视频生成超时 (task_id={task_id}, 已等待 {self.max_polls * self.poll_interval}s)")

    # ─── 下载视频 ───

    @staticmethod
    def _download_video(video_url: str, save_path: str) -> None:
        """从 URL 下载视频到本地"""
        save_dir = os.path.dirname(save_path)
        if save_dir:
            os.makedirs(save_dir, exist_ok=True)
        # 下载也用 TLS 安全 Session
        dl_session = _build_session(max_retries=2)
        resp = dl_session.get(video_url, stream=True, timeout=600)
        resp.raise_for_status()
        with open(save_path, "wb") as f:
            for chunk in resp.iter_content(chunk_size=8192):
                if chunk:
                    f.write(chunk)
        logger.info(f"KlingVideoClient: 视频已保存: {save_path}")

View on GitHub (pinned to 848b054e4f)

Solutions

  1. Increase max_polls or poll_interval on the client so total wait covers pro-mode/long-duration generation (e.g. 15-30 minutes).
  2. Check the task via the Kling console or a manual GET /v1/videos/{endpoint}/{task_id} — the task may still complete after the timeout; query it once more and use the result if succeeded.
  3. Use std mode or shorter duration when latency matters; pro + 15s is the slowest combination.
  4. If the task is genuinely stuck (processing far beyond normal), resubmit a new task; the old task_id can be discarded.

Example fix

# before
client = KlingVideoClient(max_polls=60, poll_interval=5)  # 最长等待 300s
# after
client = KlingVideoClient(max_polls=120, poll_interval=10)  # 最长等待 1200s
Defensive patterns

Strategy: retry

Validate before calling

# 估算所需等待时间,确保配置足够
needed = 30 * 60  # pro 模式长时长生成可达 30 分钟
assert client.max_polls * client.poll_interval >= needed, "轮询预算不足"

Try / catch

try:
    url = client.generate_video(...)
except TimeoutError as e:
    logger.warning(f"轮询超时,任务可能仍在进行: {e}")
    # 稍后手动复查一次任务状态,或加大 max_polls 后重试
    time.sleep(300)
    result = client._query_task(task_id, endpoint=endpoint)
    if result.get("task_status") == "succeed":
        ...

Prevention

When it happens

Trigger: All attempts in range(self.max_polls) return task_status in ('submitted','processing') (video_kling.py:304-322). Typical with pro-mode or long-duration (15s) generations on kling-v3, or when max_polls*poll_interval is shorter than Kling's actual generation time under load.

Common situations: Peak-hour Kling queue delays pushing generation beyond the configured timeout, pro mode + long duration combos, overly tight max_polls/poll_interval settings in the client config, or a stuck task that never transitions (rare) — the timeout surfaces it.

Related errors


AI-assisted analysis of ATH-MaaS/Pixelle-Video@848b054e4f (2026-08-30). Data as JSON: /api/errors/27d59289b6ae10ac. Report an issue: GitHub.