Skip to content

Export All Worker

app.infrastructure.export.export_all_worker

View source code

Batch export orchestrator — detects, tracks, and exports multiple sessions sequentially.

See Also

Layer: Infrastructure. Context: Implements concrete processing and I/O behind application-facing contracts.

ExportAllWorker

Bases: QThread

Background QThread that orchestrates full detect -> track -> export pipeline for multiple sessions.

ATTRIBUTE DESCRIPTION
_app

Application instance containing session managers and services.

TYPE: Application

_s_ids

Session IDs to process.

TYPE: list[SessionId]

_output_dir

Output directory for exported videos.

TYPE: str

_prefix

Filename prefix applied to each export.

TYPE: str

_suffix

Filename suffix applied before the .mp4 extension.

TYPE: str

_stop_requested

True when batch cancellation is requested.

TYPE: bool

_current_s_id

Session currently being processed.

TYPE: SessionId | None

Note

Signals emitted by this worker: | session_started(s_id): Emitted when session processing begins. | session_finished(s_id): Emitted when a session succeeds. | session_failed(s_id, error_msg): Emitted when a session fails. | progress_updated(sessions_done, total_sessions): Per-session progress. | session_export_progress_updated(s_id, current_frame, total_frames): Per-frame export progress. | finished_processing(): Emitted when all sessions are done or cancelled. | cancelled(): Emitted if the batch is cancelled.

Pipeline per session: 1. Detection: if Layer A is empty, run start_detection_worker(), wait, and sync the cache. 2. Tracking: if Layer C is empty, run start_tracking_worker() and wait. 3. Export: call export_session() with progress callbacks. 4. Repeat sequentially for the next session.

Cancellation stops current workers but does not abort an in-progress export. Session identifiers use Python-object signal payloads to preserve SessionId across queued Qt connections without QString conversion.

Example

s_ids = [SessionId(...), SessionId(...)] worker = ExportAllWorker(app, s_ids, "output", "prefix_", "_suffix") worker.session_finished.connect(on_session_done) worker.start() worker.stop()

PARAMETER DESCRIPTION
app

Application used to look up sessions, prepare detection/tracking output, and export each video.

TYPE: Application

s_ids

Session identifiers to export.

TYPE: list[SessionId]

output_dir

Directory receiving exported videos.

TYPE: str

prefix

Prefix added to output filenames.

TYPE: str

suffix

Suffix added to output filenames.

TYPE: str

parent

Optional Qt parent object.

TYPE: QObject | None DEFAULT: None

cancelled = Signal() class-attribute instance-attribute

finished_processing = Signal() class-attribute instance-attribute

progress_updated = Signal(int, int) class-attribute instance-attribute

session_export_progress_updated = Signal(object, int, int) class-attribute instance-attribute

session_failed = Signal(object, str) class-attribute instance-attribute

session_finished = Signal(object) class-attribute instance-attribute

session_started = Signal(object) class-attribute instance-attribute

__init__(app: Application, s_ids: list[SessionId], output_dir: str, prefix: str, suffix: str, parent: QObject | None = None) -> None

run() -> None

Main thread loop — process each session sequentially (detect -> track -> export).

Note

Workflow per session: 1. Emit session_started(s_id). 2. Call _process_session(s_id). 3. Emit session_finished(s_id) or session_failed(s_id, error). 4. Emit progress_updated(idx + 1, total). 5. Repeat for the next session. 6. If stopped early, emit cancelled() before finished_processing().

stop() -> None

Request early stop (stops current workers, doesn't cancel in-progress export).