Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

feat: improve task status polling with timeout handling and logging

myhloli84d1384c2b73
diff --git a/mineru/cli/api_client.py b/mineru/cli/api_client.py
index 0214b449..63d91eff 100644
--- a/mineru/cli/api_client.py
+++ b/mineru/cli/api_client.py
@@ -489,7 +489,17 @@ async def wait_for_task_result(
) -> None:
deadline = asyncio.get_running_loop().time() + timeout_seconds
while asyncio.get_running_loop().time() < deadline:
- response = await client.get(submit_response.status_url)
+ try:
+ response = await client.get(submit_response.status_url)
+ except httpx.ReadTimeout:
+ logger.warning(
+ "Timed out while polling task status for {} (task_id={}). "
+ "This can happen during cold start; retrying until the task deadline.",
+ task_label,
+ submit_response.task_id,
+ )
+ await asyncio.sleep(TASK_STATUS_POLL_INTERVAL_SECONDS)
+ continue
if response.status_code != 200:
raise click.ClickException(
f"Failed to query task status for {task_label}: "
diff --git a/mineru/utils/pdf_image_tools.py b/mineru/utils/pdf_image_tools.py
index 76035ebd..00ab4fc3 100644
--- a/mineru/utils/pdf_image_tools.py
+++ b/mineru/utils/pdf_image_tools.py
@@ -142,7 +142,6 @@ def _load_images_from_pdf_bytes_range(
)
executor = ProcessPoolExecutor(max_workers=actual_threads)
- cancel_futures = False
try:
futures = []
future_to_range = {}
@@ -160,7 +159,6 @@ def _load_images_from_pdf_bytes_range(
_, not_done = wait(futures, timeout=timeout, return_when=ALL_COMPLETED)
if not_done:
- cancel_futures = True
_terminate_executor_processes(executor)
raise TimeoutError(
f"PDF image rendering timeout after {timeout}s "
@@ -180,14 +178,11 @@ def _load_images_from_pdf_bytes_range(
return images_list
except Exception as exc:
- cancel_futures = True
if not isinstance(exc, TimeoutError):
_terminate_executor_processes(executor)
raise
finally:
- # Block until worker processes are fully reaped so multiprocessing
- # can unregister its semaphores before interpreter shutdown.
- executor.shutdown(wait=True, cancel_futures=cancel_futures)
+ executor.shutdown(wait=False, cancel_futures=True)
def _terminate_executor_processes(executor):