ETA

ETA estimates time remaining from the average rate since start.

It divides the elapsed time by the work done so far and extrapolates: the plain, whole-run average, so it reacts slowly to a rate that changes mid-run. ProgressBar’s own default widget set uses SmoothingETA, not this widget.

class progressbar.widgets.ETA(format_not_started='ETA:  --:--:--', format_finished='Time: %(elapsed)8s', format='ETA:  %(eta)8s', format_zero='ETA:  00:00:00', format_na='ETA:      N/A', **kwargs)[source]

Bases: Timer

WidgetBase which attempts to estimate the time of arrival.

Create an ETA, rewriting a legacy bare %s placeholder.

Parameters:
  • format_not_started – Format used before any progress has been made (value == min_value).

  • format_finished – Format used once the bar has finished.

  • format – Format used once an ETA is available.

  • format_zero – Format used when elapsed time is exactly zero.

  • format_na – Format used when no ETA can be computed (unknown max_value).

  • **kwargs – Forwarded to the next class in the cooperative __init__ chain.

Rewrites a legacy bare %s placeholder to the named %(eta)s form (see Timer.__init__ for the same elapsed-time shim).

Example

ETA
"""``ETA`` estimates time remaining from the average rate since start.

It divides the elapsed time by the work done so far and extrapolates --
the plain, whole-run average. That average reacts slowly to a rate that
changes mid-run -- see ``AdaptiveETA`` (recent window) and
``SmoothingETA`` (exponential average) for estimates that track recent
speed instead, and ``AbsoluteETA`` for a clock time instead of a
countdown. Note that ``ProgressBar``'s own default widget set uses
``SmoothingETA``, not this widget.

This example runs longer than most in this set: the ETA is only shown to
whole-second resolution, so a bar that finishes in a few milliseconds would
show a countdown stuck at ``0:00:00`` -- the estimate this widget exists to
compute would never visibly move.
"""

import time

import progressbar

STEPS = 24


def main() -> None:
    widgets = [
        progressbar.Percentage(),
        ' ',
        progressbar.Bar(),
        ' ',
        progressbar.ETA(),
    ]
    with progressbar.ProgressBar(max_value=STEPS, widgets=widgets) as bar:
        for step in range(STEPS):
            bar.update(step + 1)
            time.sleep(0.3)


if __name__ == '__main__':
    main()

See also

  • AdaptiveETA: a recent-window estimate that reacts to pace changes.

  • SmoothingETA: an exponential-moving-average estimate, the library default.

  • AbsoluteETA: a clock time instead of a countdown.

  • Timer: elapsed time only, no max_value required.