Skip to content

progress.workers

The progress of the activities which run in a worker process.

A run which hands its work to a pool (the experiments of a runner, the runs of a fit, the scans of an identifiability) sees the progress of its workers through a queue: the worker puts a Snapshot of every activity on it, see worker_reporting, and a thread of the parent replays the snapshots on its reporter, see forwarding. The activities of a worker nest under the activity of the parent, so the bar of a scan of a worker is drawn below the bar of the run which waits for it.

The queue of the parent may carry other messages as well, e.g. the events of the experiments of sbmlsim.experiment.progress, which the thread hands to a listener: one queue and one thread carry the progress of a run.

Snapshot dataclass

Snapshot(
    pid,
    uid,
    parent_uid,
    kind,
    label,
    completed,
    total,
    workers,
    elapsed,
    state,
    error,
)

What an activity of a worker is at, the message of the queue.

The snapshot holds what a reporter renders, not the activity itself: the activity of a worker lives in its process, and the parent builds one of its own from the snapshots, see forwarding.

Attributes:

Name Type Description
pid int

the process the activity runs in, which identifies it with uid.

uid int

the activity in its process.

parent_uid int | None

the activity it runs in, None for the outermost one of the worker.

kind str

what kind of operation it is.

label str

what it runs on.

completed int

the steps which are done.

total int | None

the steps in total, None while they are not known.

workers int

the steps which are processed at once.

elapsed float

the seconds since the activity started.

state str

started, running or finished.

error str | None

what the activity failed by, None if it did not.

QueueReporter

QueueReporter(messages)

Put the activities of a worker on the queue of its parent.

Create the reporter of a worker.

Parameters:

Name Type Description Default
messages Any

the queue to the parent.

required

started

started(activity)

Report that an activity started.

advanced

advanced(activity)

Report a step of an activity.

finished

finished(activity, error)

Report that an activity ended, and what it ended by.

worker_reporting

worker_reporting(messages)

Report the activities of a worker to the queue of its parent.

Parameters:

Name Type Description Default
messages Any | None

the queue to the parent, None for a worker without one, which reports nothing.

required

forwarding

forwarding(
    messages,
    *,
    target=None,
    listener=None,
    parent=None,
    poll=POLL,
    close=False,
)

Forward the messages of the workers while the run lasts.

A thread of the parent takes the messages from the queue: a Snapshot is replayed on the reporter, every other message is handed to the listener. A worker which is terminated while it writes, e.g. when Ctrl-C stops the pool, can leave a message half written, which the thread waits for in vain: it is a daemon and is not waited for longer than a second, so it never holds up the end of a run.

Parameters:

Name Type Description Default
messages Any | None

the queue of the workers, None for a run without one.

required
target Reporter | None

what renders the activities of the workers, None for a run which renders none.

None
listener Callable[[Any], None] | None

what receives the other messages of the queue, None for a run which has none.

None
parent Activity | None

the activity the activities of the workers nest under.

None
poll float

the seconds the thread waits for the next message.

POLL
close bool

close the queue when the run ends, for a queue of a pool which is not used again.

False