From fa261c90ee81bb708aa049e6baf7e22d6bcef850 Mon Sep 17 00:00:00 2001 From: Elijah Duffy Date: Thu, 26 Mar 2026 23:39:54 -0700 Subject: [PATCH] fix per slide timeout ignoring base config --- .../src/officeconvert/conversion.py | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/python/packages/officeconvert/src/officeconvert/conversion.py b/python/packages/officeconvert/src/officeconvert/conversion.py index 16649fc..7ec2828 100644 --- a/python/packages/officeconvert/src/officeconvert/conversion.py +++ b/python/packages/officeconvert/src/officeconvert/conversion.py @@ -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(