Skip to content

terminal

terminal #

print_progress — draw the process's open steps in a terminal for the block.

A terminal gets the tree redrawn in place ten times a second: every open step with its elapsed time, its count as a bar, and its note; a finished map or top-level step stays as a done line. Anything that is not a terminal gets one line as a step opens and one as it closes.

print_progress(stream=None) #

Show what the block is doing in the terminal.

with cg.print_progress():
    thumbnails = journal.sessions.photo.pmap(session_thumbnail)

Parameters:

Name Type Description Default
stream IO[str] | None

Where to draw; sys.stderr by default.

None
Source code in capturegraph-lib/capturegraph/recipes/progress/terminal.py
@contextmanager
def print_progress(stream: IO[str] | None = None) -> Iterator[None]:
    """Show what the block is doing in the terminal.

    ```python
    with cg.print_progress():
        thumbnails = journal.sessions.photo.pmap(session_thumbnail)
    ```

    Args:
        stream: Where to draw; ``sys.stderr`` by default.
    """
    printer = _Printer(stream if stream is not None else sys.stderr)
    registry.watch(printer)
    try:
        yield
    finally:
        registry.unwatch(printer)
        printer.finish()