---
title: "tomojax.progress"
description: "Synchronous progress events and cooperative cancellation."
canonical: "https://tomojax.dev/api/progress/"
last-updated: "2026-11-28"
---

# tomojax.progress

> For the complete documentation index, see [llms.txt](https://tomojax.dev/llms.txt).

| Name | Summary |
| --- | --- |
| [`Advanced`](https://tomojax.dev/api/progress/#advanced) | Completed units and a snapshot of the associated diagnostics. |
| [`Canceled`](https://tomojax.dev/api/progress/#canceled) | The operation stopped at a work boundary. |
| [`Control`](https://tomojax.dev/api/progress/#control) | Coordinate pause, resume and cancellation between an owner and a controller. |
| [`Event`](https://tomojax.dev/api/progress/#event) |  |
| [`Finished`](https://tomojax.dev/api/progress/#finished) | The outcome of an operation. |
| [`Note`](https://tomojax.dev/api/progress/#note) | A message from the watched code. |
| [`Paused`](https://tomojax.dev/api/progress/#paused) | A task reached a work boundary while paused. |
| [`Placed`](https://tomojax.dev/api/progress/#placed) | The coordinator resolved the devices participating in a task. |
| [`Preview`](https://tomojax.dev/api/progress/#preview) | Coherent small arrays copied at one completed work boundary. |
| [`Resumed`](https://tomojax.dev/api/progress/#resumed) | A paused task resumed computation. |
| [`Started`](https://tomojax.dev/api/progress/#started) | An operation entered by its calling thread. |
| [`to_json`](https://tomojax.dev/api/progress/#to_json) | Return a versioned JSON-compatible record for an event. |
| [`watch`](https://tomojax.dev/api/progress/#watch) | Deliver events synchronously to a fast handler in the calling context. |

## `Advanced` [#advanced]

```python
class Advanced(
    task: int,
    done: int,
    total: int | None,
    metrics: Mapping[str, _Metric],
    time: float,
    eta: float | None = None,
)
```

<small>Defined in [src/tomojax/progress.py:110](https://github.com/tristanmanchester/tomojax/blob/main/src/tomojax/progress.py#L110)</small>

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` [#canceled]

```python
class Canceled(message: str = 'canceled', *, checkpoint: str | None = None)
```

<small>Defined in [src/tomojax/errors.py:35](https://github.com/tristanmanchester/tomojax/blob/main/src/tomojax/errors.py#L35)</small>

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` [#control]

```python
class Control()
```

<small>Defined in [src/tomojax/progress.py:286](https://github.com/tristanmanchester/tomojax/blob/main/src/tomojax/progress.py#L286)</small>

Coordinate pause, resume and cancellation between an owner and a controller.

### `Control.pause` [#controlpause]

```python
pause() -> None
```

Request a pause at the next work boundary.

### `Control.resume` [#controlresume]

```python
resume() -> None
```

Wake the paused operation or withdraw a pending pause.

### `Control.cancel` [#controlcancel]

```python
cancel() -> None
```

Request cancellation and wake a paused operation.

Inside a checkpointed loop, the loop saves at its next work boundary
before raising [`Canceled`](https://tomojax.dev/api/progress/#canceled).

### `Control.state` [#controlstate]

```python
@property
state: _State
```

Return the cooperative state of the active operation.

**Returns**

- *str*: Running, pause-requested or paused.

### `Control.canceled` [#controlcanceled]

```python
@property
canceled: bool
```

Whether cancellation has been requested.

**Returns**

- *bool*: True once cancellation has been requested.

### `Control.deferring` [#controldeferring]

```python
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`](https://tomojax.dev/api/progress/#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` [#controlboundary]

```python
boundary() -> None
```

Mark a work boundary: block while paused, or raise when canceled.

**Raises**

- *Canceled*: If the operation was canceled, unless a checkpointed loop defers it.

## `Event` [#event]

<small>Defined in [src/tomojax/progress.py:282](https://github.com/tristanmanchester/tomojax/blob/main/src/tomojax/progress.py#L282)</small>



## `Finished` [#finished]

```python
class Finished(task: int, status: _Status, time: float)
```

<small>Defined in [src/tomojax/progress.py:141](https://github.com/tristanmanchester/tomojax/blob/main/src/tomojax/progress.py#L141)</small>

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` [#note]

```python
class Note(task: int | None, level: NoteLevel, message: str, time: float)
```

<small>Defined in [src/tomojax/progress.py:211](https://github.com/tristanmanchester/tomojax/blob/main/src/tomojax/progress.py#L211)</small>

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` [#paused]

```python
class Paused(task: int, time: float)
```

<small>Defined in [src/tomojax/progress.py:179](https://github.com/tristanmanchester/tomojax/blob/main/src/tomojax/progress.py#L179)</small>

A task reached a work boundary while paused.

**Parameters**

- **`task`** (*int*): Innermost active task.
- **`time`** (*float*): Monotonic seconds since the watch began.

## `Placed` [#placed]

```python
class Placed(task: int, devices: tuple[str, ...], time: float)
```

<small>Defined in [src/tomojax/progress.py:160](https://github.com/tristanmanchester/tomojax/blob/main/src/tomojax/progress.py#L160)</small>

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` [#preview]

```python
class Preview(task: int, arrays: Mapping[str, Sample], time: float)
```

<small>Defined in [src/tomojax/progress.py:263](https://github.com/tristanmanchester/tomojax/blob/main/src/tomojax/progress.py#L263)</small>

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` [#resumed]

```python
class Resumed(task: int, time: float)
```

<small>Defined in [src/tomojax/progress.py:195](https://github.com/tristanmanchester/tomojax/blob/main/src/tomojax/progress.py#L195)</small>

A paused task resumed computation.

**Parameters**

- **`task`** (*int*): Innermost active task.
- **`time`** (*float*): Monotonic seconds since the watch began.

## `Started` [#started]

```python
class Started(
    task: int,
    parent: int | None,
    name: _Name,
    label: str,
    total: int | None,
    unit: str,
    time: float,
)
```

<small>Defined in [src/tomojax/progress.py:79](https://github.com/tristanmanchester/tomojax/blob/main/src/tomojax/progress.py#L79)</small>

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]

```python
to_json(event: Event, *, directory: str | Path | None = None) -> dict[str, object]
```

<small>Defined in [src/tomojax/progress.py:393](https://github.com/tristanmanchester/tomojax/blob/main/src/tomojax/progress.py#L393)</small>

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]

```python
watch(
    handler: Callable[[Event], None],
    *,
    control: Control | None = None,
    previews: bool = False,
) -> Iterator[None]
```

<small>Defined in [src/tomojax/progress.py:747](https://github.com/tristanmanchester/tomojax/blob/main/src/tomojax/progress.py#L747)</small>

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.
