progress_tap
anomaly_match_ui.utils.progress_tap
¶
Loguru-sink helper for turning log stream into structured UI progress events.
The training and prediction subprocesses already emit per-batch progress via
tqdm; :class:Session._launch_prediction_subprocess relays every subprocess
stdout line through logger.info("[subprocess] {}", line) so the lines flow
into the main kernel's loguru stream (and into the screen's Output widget).
This module lets a UI screen tap that stream read-only — without touching the
background thread that produced the line — to extract 71/93 style progress
counts and any cutana module messages that are useful as spinner captions.
The tap is a loguru sink, so installing and removing it has no effect on the
background work; it simply forks a copy of the log messages to the supplied
callbacks.
LogProgressTap(*, on_tqdm=None, on_cutana_hint=None)
¶
A loguru sink that forks log messages to progress-aware callbacks.
Install once when a long-running operation starts, uninstall on completion. The sink runs in whichever thread loguru dispatches from (usually the thread that produced the message), so callbacks must be cheap and widget updates must be safe to perform from a non-UI thread — which is the case for ipywidgets attribute writes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
on_tqdm
|
Callable[[dict], None] | None
|
Optional callback invoked with the parsed dict from
:func: |
None
|
on_cutana_hint
|
Callable[[str], None] | None
|
Optional callback invoked with the raw message
text when the line matches :func: |
None
|
Source code in anomaly_match_ui/utils/progress_tap.py
install()
¶
Attach the sink to the shared loguru logger.
Calling this twice without an intervening :meth:uninstall is a
no-op so callers don't need to track state.
Source code in anomaly_match_ui/utils/progress_tap.py
uninstall()
¶
Detach the sink. Safe to call multiple times.
Source code in anomaly_match_ui/utils/progress_tap.py
clean_hint_text(text)
¶
Return text with any relayed subprocess loguru header removed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
A log line matched by :func: |
required |
Returns:
| Type | Description |
|---|---|
str
|
Just the human-readable message, suitable for a status label. |
Source code in anomaly_match_ui/utils/progress_tap.py
parse_tqdm_line(text)
¶
Extract a tqdm progress event from a single log line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Raw log message text (without loguru formatting). |
required |
Returns:
| Type | Description |
|---|---|
dict | None
|
Dict with |
dict | None
|
keys when text looks like a tqdm status line; |
Source code in anomaly_match_ui/utils/progress_tap.py
looks_like_cutana_status(text)
¶
Return True when text matches one of the known Cutana status hints.