fix per slide timeout ignoring base config

This commit is contained in:
2026-03-26 23:39:54 -07:00
parent baf87ee195
commit fa261c90ee
@@ -102,6 +102,7 @@ def render_pdf_to_images(
image_format: str = "png", image_format: str = "png",
timeout_s: int = 120, timeout_s: int = 120,
total_pages: int | None = None, total_pages: int | None = None,
operation_timeout_s: int | None = None,
page_progress_callback: PageProgressCallback | None = None, page_progress_callback: PageProgressCallback | None = None,
) -> list[Path]: ) -> list[Path]:
"""Render each PDF page into an image using Poppler's `pdftoppm`. """Render each PDF page into an image using Poppler's `pdftoppm`.
@@ -146,7 +147,7 @@ def render_pdf_to_images(
raise RuntimeError( raise RuntimeError(
"Poppler rasterization timed out after " "Poppler rasterization timed out after "
f"{timeout_s} seconds while rendering {pdf_path.name}; " f"{timeout_s} seconds while rendering {pdf_path.name}; "
"increase conversion PDF render timeout or lower image DPI" "increase conversion PDF render timeout cap or lower image DPI"
) from exc ) from exc
if completed.returncode != 0: if completed.returncode != 0:
raise RuntimeError( raise RuntimeError(
@@ -181,11 +182,16 @@ def render_pdf_to_images(
timeout=timeout_s, timeout=timeout_s,
) )
except subprocess.TimeoutExpired as exc: except subprocess.TimeoutExpired as exc:
timeout_context = (
f"per-page timeout {timeout_s}s "
f"(total operation cap {operation_timeout_s}s for {total_pages} pages)"
if operation_timeout_s is not None
else f"per-page timeout {timeout_s}s"
)
raise RuntimeError( raise RuntimeError(
"Poppler rasterization timed out after " "Poppler rasterization timed out while rendering page "
f"{timeout_s} seconds while rendering page {page_index} " f"{page_index}/{total_pages} of {pdf_path.name}; "
f"of {pdf_path.name}; increase conversion PDF render timeout " f"{timeout_context}. Increase timeout settings or lower image DPI."
"or lower image DPI"
) from exc ) from exc
if completed.returncode != 0: if completed.returncode != 0:
raise RuntimeError( raise RuntimeError(
@@ -300,8 +306,10 @@ def convert_pptx_to_slidedeck(
timeout_s=_compute_page_timeout( timeout_s=_compute_page_timeout(
total_timeout_s=pdf_to_images_timeout, total_timeout_s=pdf_to_images_timeout,
page_count=slide_count, page_count=slide_count,
base_timeout_s=pdf_to_images_base_timeout_s,
), ),
total_pages=slide_count, total_pages=slide_count,
operation_timeout_s=pdf_to_images_timeout,
page_progress_callback=lambda current, max_pages: _emit_progress( page_progress_callback=lambda current, max_pages: _emit_progress(
progress_callback, progress_callback,
PHASE_PDF_TO_IMAGES, PHASE_PDF_TO_IMAGES,
@@ -337,12 +345,17 @@ def _compute_adaptive_timeout(
return max(1, bounded_timeout) return max(1, bounded_timeout)
def _compute_page_timeout(*, total_timeout_s: int, page_count: int) -> int: def _compute_page_timeout(
*,
total_timeout_s: int,
page_count: int,
base_timeout_s: int,
) -> int:
"""Split total PDF raster timeout into a bounded per-page timeout.""" """Split total PDF raster timeout into a bounded per-page timeout."""
if page_count <= 0: if page_count <= 0:
return max(1, total_timeout_s) return max(1, total_timeout_s)
timeout = (total_timeout_s + page_count - 1) // page_count timeout = (total_timeout_s + page_count - 1) // page_count
return max(15, timeout) return max(base_timeout_s, timeout)
def _emit_progress( def _emit_progress(