From 16b7a79a488e01650f6d577a3f58dccc0e4bed89 Mon Sep 17 00:00:00 2001 From: Sleeps Date: Wed, 7 Oct 2026 12:30:15 +0100 Subject: [PATCH] Pause caption jobs during routing and between captions --- scene_search/caption_jobs.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/scene_search/caption_jobs.py b/scene_search/caption_jobs.py index 12f1b54..81e0b30 100644 --- a/scene_search/caption_jobs.py +++ b/scene_search/caption_jobs.py @@ -88,16 +88,19 @@ class CaptionJobManager: self._state["pause_requested"] = False self._state["paused"] = False if self._state.get("stage") == "paused": - self._state["stage"] = "captioning" + self._state["stage"] = str( + self._state.get("paused_from_stage") or "captioning" + ) return self.status() - def _wait_if_paused(self) -> None: + def _wait_if_paused(self, resume_stage: str = "captioning") -> None: if not self._pause_requested.is_set(): return with self._state_lock: self._state["paused"] = True self._state["pause_requested"] = True + self._state["paused_from_stage"] = resume_stage self._state["stage"] = "paused" while self._pause_requested.is_set(): @@ -107,7 +110,7 @@ class CaptionJobManager: self._state["paused"] = False self._state["pause_requested"] = False if self._state.get("running"): - self._state["stage"] = "captioning" + self._state["stage"] = resume_stage def start(self, library_ids: list[str], *, force: bool = False) -> dict[str, Any]: library_ids = [str(value).strip() for value in library_ids if str(value).strip()] @@ -219,6 +222,7 @@ class CaptionJobManager: rows, progress=self._progress, frame_source=frame_source, + before_batch=lambda: self._wait_if_paused("routing"), ) finally: self._set_gpu_busy(False) @@ -293,7 +297,7 @@ class CaptionJobManager: progress=general_progress, total_frames=frames_total, frame_source=frame_source, - before_frame=self._wait_if_paused, + before_frame=lambda: self._wait_if_paused("captioning"), ) if specialist_rows: @@ -317,13 +321,13 @@ class CaptionJobManager: completed_offset=general_done, total_frames=frames_total, frame_source=frame_source, - before_frame=self._wait_if_paused, + before_frame=lambda: self._wait_if_paused("captioning"), ) completed = general_done + specialist_done failed = missing + general_failed + specialist_failed - self._wait_if_paused() + self._wait_if_paused("captioning") self._progress( {