Show progress when the total isn’t known¶
A percentage and an ETA both need a total to measure against – neither means anything for a job whose length you can’t compute in advance, such as scanning a filesystem or reading a stream.
"""Show progress for work whose total length isn't known in advance.
Pass `max_value=progressbar.UnknownLength` and include an `AnimatedMarker`
so there is still something visibly moving -- there is no percentage or
ETA to show without a known total to measure against.
"""
import time
import progressbar
STEPS = 24
def main() -> None:
widgets = [
'Scanning: ',
progressbar.AnimatedMarker(),
' ',
progressbar.Counter(),
' files found',
]
with progressbar.ProgressBar(
max_value=progressbar.UnknownLength, widgets=widgets
) as bar:
for step in range(STEPS):
bar.update(step + 1)
time.sleep(0.005)
if __name__ == '__main__':
main()
Pass max_value=progressbar.UnknownLength and include an
AnimatedMarker (or another marker-style widget) so there is still
something visibly moving even without a percentage to report. A
Counter() widget still works normally here, since it just echoes
value rather than computing a fraction of max_value.