fix per slide timeout ignoring base config
This commit is contained in:
@@ -102,6 +102,7 @@ def render_pdf_to_images(
|
||||
image_format: str = "png",
|
||||
timeout_s: int = 120,
|
||||
total_pages: int | None = None,
|
||||
operation_timeout_s: int | None = None,
|
||||
page_progress_callback: PageProgressCallback | None = None,
|
||||
) -> list[Path]:
|
||||
"""Render each PDF page into an image using Poppler's `pdftoppm`.
|
||||
@@ -146,7 +147,7 @@ def render_pdf_to_images(
|
||||
raise RuntimeError(
|
||||
"Poppler rasterization timed out after "
|
||||
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
|
||||
if completed.returncode != 0:
|
||||
raise RuntimeError(
|
||||
@@ -181,11 +182,16 @@ def render_pdf_to_images(
|
||||
timeout=timeout_s,
|
||||
)
|
||||
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(
|
||||
"Poppler rasterization timed out after "
|
||||
f"{timeout_s} seconds while rendering page {page_index} "
|
||||
f"of {pdf_path.name}; increase conversion PDF render timeout "
|
||||
"or lower image DPI"
|
||||
"Poppler rasterization timed out while rendering page "
|
||||
f"{page_index}/{total_pages} of {pdf_path.name}; "
|
||||
f"{timeout_context}. Increase timeout settings or lower image DPI."
|
||||
) from exc
|
||||
if completed.returncode != 0:
|
||||
raise RuntimeError(
|
||||
@@ -300,8 +306,10 @@ def convert_pptx_to_slidedeck(
|
||||
timeout_s=_compute_page_timeout(
|
||||
total_timeout_s=pdf_to_images_timeout,
|
||||
page_count=slide_count,
|
||||
base_timeout_s=pdf_to_images_base_timeout_s,
|
||||
),
|
||||
total_pages=slide_count,
|
||||
operation_timeout_s=pdf_to_images_timeout,
|
||||
page_progress_callback=lambda current, max_pages: _emit_progress(
|
||||
progress_callback,
|
||||
PHASE_PDF_TO_IMAGES,
|
||||
@@ -337,12 +345,17 @@ def _compute_adaptive_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."""
|
||||
if page_count <= 0:
|
||||
return max(1, total_timeout_s)
|
||||
timeout = (total_timeout_s + page_count - 1) // page_count
|
||||
return max(15, timeout)
|
||||
return max(base_timeout_s, timeout)
|
||||
|
||||
|
||||
def _emit_progress(
|
||||
|
||||
Reference in New Issue
Block a user