Skip to content

Progress

progress

Defines themed Rich progress bars for server-side oprations

One Shared Display
  • File uploads and Modal volume transfers report their byte progress through transfer_bar, a context manager that yields an advance callable

  • All bars share a single rich.progress.Progress object (obtained lazily via _progress_display_manager) drawn on the shared console, so concurrent transfers (batches) render as stacked tasks in one display instead of fighting over stdout

  • On a non-interactive stream (the server under Docker / uvicorn) the bars are a no-op, so nothing is written except the surrounding LOGGER lines

Advance = Callable[[int], None] module-attribute

The signature of the advance callback called by each tracked-progress operation with the number representing how much to advance the progress counter

CountingReader

A transparent binary-reader proxy that reports every read to an Advance callable

Why
  • The chunked uploader (Modal's batch_upload) reads a source file itself, so the caller has no per-chunk hook to advance a progress bar

  • Wrapping the file in this proxy makes each read also report the number of bytes returned, so the bar advances as the uploader consumes the file, without changing how the uploader reads

Transparency
  • Only read is intercepted

  • Every other attribute (seek, tell, close, mode, ...) is delegated to the wrapped file via __getattr__, so the proxy still behaves like the binary stream the uploader expects

__getattr__(name)

Delegates any non-intercepted attribute to the wrapped file

Only reached for attributes not defined on the proxy itself (so not read), which keeps seek / tell / close / ... pointing at the real file

Parameters:

Name Type Description Default
name str

The attribute being accessed

required

Returns:

Type Description
object

The corresponding attribute of the wrapped binary file

__init__(raw, advance)

Constructs the proxy

Parameters:

Name Type Description Default
raw BinaryIO

The real binary file object to read from

required
advance Advance

Called with the byte count of each read

required

read(size=-1)

Reads from the wrapped file and advances the bar by the bytes read

Parameters:

Name Type Description Default
size int

Maximum number of bytes to read, or -1 for the rest of the file

-1

Returns:

Type Description
bytes

The bytes read, empty at end of file

transfer_bar(description, total=None)

Shows a themed byte-transfer progress bar for the duration of the block

Parameters:

Name Type Description Default
description str

The bar label

required
total int | None

The total byte count, or None when unknown

None

Yields:

Type Description
Advance

A callable which advances the bar by a number of bytes