Accept: text/markdown.tomojax.progress
Synchronous progress events and cooperative cancellation.
| Name | Summary |
|---|---|
Advanced | Completed units and a snapshot of the associated diagnostics. |
Canceled | The operation stopped at a work boundary. |
Control | Coordinate pause, resume and cancellation between an owner and a controller. |
Event | |
Finished | The outcome of an operation. |
Note | A message from the watched code. |
Paused | A task reached a work boundary while paused. |
Placed | The coordinator resolved the devices participating in a task. |
Preview | Coherent small arrays copied at one completed work boundary. |
Resumed | A paused task resumed computation. |
Started | An operation entered by its calling thread. |
to_json | Return a versioned JSON-compatible record for an event. |
watch | Deliver events synchronously to a fast handler in the calling context. |
Advanced
class Advanced(
task: int,
done: int,
total: int | None,
metrics: Mapping[str, _Metric],
time: float,
eta: float | None = None,
)Completed units and a snapshot of the associated diagnostics.
Parameters
task(int): Task identifier.done(int): Number of completed units.total(int or None): Current estimate of the total units, if known.metrics(mapping): Snapshot of scalar diagnostics for the completed work.time(float): Monotonic seconds since the watch began.eta(float or None, optional): Remaining active seconds at the measured completion rate.
Canceled
class Canceled(message: str = 'canceled', *, checkpoint: str | None = None)The operation stopped at a work boundary.
Parameters
message(str, optional): Why and where it stopped;"canceled"by default.checkpoint(str or None, optional): The directory holding the stopped run's saved state: the same call with this checkpoint resumes. None when the run had no checkpoint.
Control
class Control()Coordinate pause, resume and cancellation between an owner and a controller.
Control.pause
pause() -> NoneRequest a pause at the next work boundary.
Control.resume
resume() -> NoneWake the paused operation or withdraw a pending pause.
Control.cancel
cancel() -> NoneRequest cancellation and wake a paused operation.
Inside a checkpointed loop, the loop saves at its next work boundary
before raising Canceled.
Control.state
@property
state: _StateReturn the cooperative state of the active operation.
Returns
- str: Running, pause-requested or paused.
Control.canceled
@property
canceled: boolWhether cancellation has been requested.
Returns
- bool: True once cancellation has been requested.
Control.deferring
deferring() -> Iterator[None]Within, a cancel waits for the code that saves state at its own boundary.
A checkpointed loop enters this block: on cancel it saves at its next
boundary and raises Canceled itself, so the work boundaries inside
it let the cancel pass. Outside the block a cancel stops the work at the
next boundary.
Yields
- None: The extent of the deferral.
Control.boundary
boundary() -> NoneMark a work boundary: block while paused, or raise when canceled.
Raises
- Canceled: If the operation was canceled, unless a checkpointed loop defers it.
Event
Defined in src/tomojax/progress.py:282
Finished
class Finished(task: int, status: _Status, time: float)The outcome of an operation.
Parameters
task(int): Task identifier.status(str): One of done, failed or canceled.time(float): Monotonic seconds since the watch began.
Note
class Note(task: int | None, level: NoteLevel, message: str, time: float)A message from the watched code.
Parameters
task(int or None): Innermost task ID or None between operations.level(str): Severity of the message.message(str): Formatted log or warning text.time(float): Monotonic seconds since the watch began.
Paused
class Paused(task: int, time: float)A task reached a work boundary while paused.
Parameters
task(int): Innermost active task.time(float): Monotonic seconds since the watch began.
Placed
class Placed(task: int, devices: tuple[str, ...], time: float)The coordinator resolved the devices participating in a task.
Parameters
task(int): Active task identifier.devices(tuple of str): Participating device IDs in coordinator order.time(float): Monotonic seconds since the watch began.
Preview
class Preview(task: int, arrays: Mapping[str, Sample], time: float)Coherent small arrays copied at one completed work boundary.
Parameters
task(int): Owning task identifier.arrays(mapping): Named host images with axes, fixed coordinates and value units.time(float): Monotonic seconds since the watch began.
Resumed
class Resumed(task: int, time: float)A paused task resumed computation.
Parameters
task(int): Innermost active task.time(float): Monotonic seconds since the watch began.
Started
class Started(
task: int,
parent: int | None,
name: _Name,
label: str,
total: int | None,
unit: str,
time: float,
)An operation entered by its calling thread.
Parameters
task(int): Identifier unique to this watch.parent(int or None): Enclosing task, if any.name(str): The operation or numerical stage identifier.label(str): Display text for the task, preserving file names.total(int or None): Expected number of units, if known.unit(str): Unit of completed work.time(float): Monotonic seconds since the watch began.
to_json
to_json(event: Event, *, directory: str | Path | None = None) -> dict[str, object]Return a versioned JSON-compatible record for an event.
Parameters
event(Event): Progress event to encode.directory(str or pathlib.Path or None, optional): Consumer-owned directory for the NumPy arrays in a preview.
Returns
- dict: Versioned record suitable for strict JSON encoding.
watch
watch(
handler: Callable[[Event], None],
*,
control: Control | None = None,
previews: bool = False,
) -> Iterator[None]Deliver events synchronously to a fast handler in the calling context.
Parameters
handler(callable): Receives each event synchronously and must return quickly. An exception stops delivery and propagates to the caller.control(Control or None, optional): Token which another thread or the handler may set to stop the operation.previews(bool, optional): Deliver registered preview arrays from completed numerical work boundaries.
Yields
- None: The dynamic extent of this watch in the current context.