step
step
#
Step — one span of work: a label, a parent, a start time, and optionally a count.
- Open.
step(label, total)opens a step beneath the ambient one (a context variable) and makes it ambient for its block, so steps nest the way calls do, and apmapworker, running in a copy of the caller's context, attaches its steps beneath the caller's. - Advance.
advance,trackandnotechange the record under its lock and mark it dirty; nothing else happens on the calling thread. - Watch. The registry tells its watchers when a step opens or closes and
hands them a
readof any open step when they ask.
active_step = ContextVar('cg_active_step', default=None)
module-attribute
#
The step the current context is inside, if any; a new step's parent.
Reading
dataclass
#
A step's count and note at one instant.
Attributes:
| Name | Type | Description |
|---|---|---|
done |
int
|
How many units the step has advanced through. |
total |
int | None
|
How many it will, if known. |
message |
str | None
|
The last |
fields |
dict[str, JSONValue]
|
The named values the notes carried, latest per name. |
Source code in capturegraph-lib/capturegraph/recipes/progress/step.py
Step
#
One span of work; step() opens one and the methods below advance it.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
A fresh identifier. |
|
parent_id |
The ambient step's |
|
label |
What the step is doing, as a page or terminal shows it. |
|
identity |
The function identity a memoized call reports, else |
|
call_key |
The call key a memoized call reports, else |
|
workspace |
The workspace a memoized call computes in, else |
|
scratch |
Scratch | None
|
The scratch the step reports to, if one was active when it opened. |
started_at |
When the step opened, as |
Source code in capturegraph-lib/capturegraph/recipes/progress/step.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
dirty
property
#
Whether the step has changed since the last settling read.
elapsed
property
#
Seconds since the step opened.
__init__(label, total=None, *, identity=None, call_key=None, workspace=None)
#
A step not yet open, beneath the ambient step and reporting to the active scratch.
Source code in capturegraph-lib/capturegraph/recipes/progress/step.py
__repr__()
#
advance(count=1)
#
note(message=None, **fields)
#
Say what the step is doing: the last message wins, fields update by name.
Source code in capturegraph-lib/capturegraph/recipes/progress/step.py
read(*, settle=False)
#
The count and note right now; settle also clears the dirty mark.
Source code in capturegraph-lib/capturegraph/recipes/progress/step.py
track(iterable)
#
iterable, advancing this step by one as each element is consumed.
Source code in capturegraph-lib/capturegraph/recipes/progress/step.py
label_of(function)
#
The label a step takes from function: its name.
Source code in capturegraph-lib/capturegraph/recipes/progress/step.py
opened(step)
#
step open and ambient for the block, registered for the watchers.
Source code in capturegraph-lib/capturegraph/recipes/progress/step.py
step(label, total=None)
#
Open a step beneath the ambient one for the block.
with cg.step("Training splat", total=iterations) as training:
for batch in training.track(batches):
...
training.note(f"loss {loss:.3f}", loss=loss)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
What the block is doing. |
required |
total
|
int | None
|
How many units the block will |
None
|
Yields:
| Type | Description |
|---|---|
Step
|
The open step. |