anystore.io.progress
A live progress display for long-running io jobs.
Where logged_items logs the progress of a
single iterator, this renders one bar per unit of work – a key prefix, a shard,
a file – each labelled, each removed when it completes, and each carrying the
byte throughput that actually says whether a transfer is getting anywhere.
Example
from anystore import get_store
from anystore.io import SyncProgressBar
from anystore.logic.io import stream_bytes
from anystore.util import format_bytes
source, target = get_store("s3://from"), get_store("./to")
# a single bar: describe it up front and advance the display itself
with SyncProgressBar("copying", total=len(keys)) as bar:
for key in keys:
bar.advance(size=stream_bytes(key, source, target))
# or one bar per unit of concurrent work
with SyncProgressBar() as bar:
# a task fed the bar's own throughput sums up all the others
overall = bar.task(
"all prefixes", total=len(prefixes), throughput=bar.throughput
)
for prefix in prefixes: # from any number of worker threads
keys = list(source.iterate_keys(prefix=prefix))
with bar.task(prefix, total=len(keys)) as task:
for key in keys:
task.advance(size=stream_bytes(key, source, target))
overall.advance()
log.info("Done.", moved=format_bytes(bar.throughput.total))
Note
While the display is running, log output is routed through the same rich
console, which clears the bars before each line and redraws them after –
otherwise the two write over each other. This works by swapping
sys.stderr, which anystore's log handlers resolve on every emit. Pass
route_logging=False to leave logging alone.
ProgressTask
A labelled bar on a SyncProgressBar.
Use it as a context manager to have it disappear when its work is done:
Example
Source code in anystore/io/progress.py
advance(items=1, size=None)
Advance the task, optionally accounting transferred bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
int | None
|
Number of items completed (default: 1) |
1
|
size
|
int | None
|
Bytes transferred for them, added to this task's throughput and to the overall throughput of the bar |
None
|
Source code in anystore/io/progress.py
remove()
SyncProgressBar
A live display of one or more bars, with byte throughput.
For a single bar, describe it up front and advance the display itself:
Example
For concurrent work, add a bar per unit of it with
task – they may be advanced
from any thread, and all of them live in this one display, as wrapping each
bar in a display of its own would leave all but the first invisible (rich
only renders the outermost live display):
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
description
|
str | None
|
Label for the display's own bar – leave it out for the multi-task case, where each task brings its own |
None
|
total
|
int | None
|
Number of items for that bar, if known |
None
|
console
|
Console | None
|
Console to render on (default: a new one on the current
|
None
|
columns
|
Sequence[str | ProgressColumn] | None
|
Custom rich progress columns |
None
|
transient
|
bool | None
|
Remove the whole display when it's done (default: yes) |
True
|
route_logging
|
bool | None
|
Print log output through the same console while the display is running (default: yes) |
True
|
disable
|
bool | None
|
Render nothing at all, e.g. for a |
False
|
window
|
int | None
|
Seconds to average throughput rates over |
DEFAULT_WINDOW
|
Source code in anystore/io/progress.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | |
default_task
property
The display's own bar, for the single-bar case
progress
property
The underlying rich Progress, once the display is started
advance(items=1, size=None)
Advance the display's own bar, optionally accounting transferred bytes.
Only for the single-bar case – with several tasks, advance those.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
int | None
|
Number of items completed (default: 1) |
1
|
size
|
int | None
|
Bytes transferred for them |
None
|
Source code in anystore/io/progress.py
start()
Start rendering (and, unless turned off, routing log output)
Source code in anystore/io/progress.py
stop()
task(description, total=None, throughput=None)
Add a labelled bar to the display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
description
|
str
|
The label, e.g. the key prefix being worked on |
required |
total
|
int | None
|
Number of items, if known – an unknown total pulses instead of filling up |
None
|
throughput
|
Throughput | None
|
Byte counter to display, pass the bar's own
|
None
|
Returns:
| Type | Description |
|---|---|
ProgressTask
|
The task handle, removable and usable as a context manager |
Source code in anystore/io/progress.py
Throughput
Thread-safe byte counter exposing a rolling transfer rate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
int | None
|
Seconds to average the rate over |
DEFAULT_WINDOW
|
Source code in anystore/io/progress.py
rate
property
Bytes per second over the last window seconds.
ThroughputColumn
Bases: ProgressColumn
Renders the byte throughput of a task's Throughput field.
The item count says how far along a task is; this says how fast bytes are actually moving.
Source code in anystore/io/progress.py
logging_through(console)
Route log output through a rich console for the duration of the block, so log lines don't cut into whatever that console is rendering.
anystore's log handlers resolve sys.stderr on every emit, so swapping it
is enough to catch them – as well as warnings and any other library writing
to stderr.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
console
|
Console
|
The console to print through |
required |