Contents Menu Expand Light mode Dark mode Auto light/dark, in light mode Auto light/dark, in dark mode Skip to content
Progress Bar 4.6.0 documentation
Progress Bar 4.6.0 documentation

Documentation

  • Installation
  • Tutorial
    • Step 1: Wrap a loop with progressbar
    • Step 2: Update a ProgressBar explicitly
    • Step 3: Give the bar a max_value
    • Step 4: Choose your own widgets
    • Step 5: Print safely with redirect_stdout
  • How-to guides
    • Wrap an iterable without managing the bar yourself
    • Print while a bar is running
    • Send logging output above a running bar
    • Print one line per update instead of overwriting
    • Color a bar, solid or gradient
    • Write a custom widget
    • Show a custom value next to the bar
    • Put live values in the prefix or suffix
    • Switch from tqdm without renaming your keywords
    • Report a transfer’s size and speed
    • Show progress when the total isn’t known
    • Track several jobs at once with MultiBar
    • Stack independent bars without MultiBar
    • Run a batch in parallel with progress
  • Widget reference
    • AbsoluteETA
    • AdaptiveETA
    • AdaptiveTransferSpeed
    • AnimatedMarker
    • Bar
    • BouncingBar
    • Counter
    • CurrentTime
    • DataSize
    • DynamicMessage
    • ETA
    • FileTransferSpeed
    • FormatCustomText
    • FormatLabel
    • FormatLabelBar
    • GranularBar
    • JobStatusBar
    • MultiProgressBar
    • MultiRangeBar
    • Percentage
    • PercentageLabelBar
    • Postfix
    • ReverseBar
    • RotatingMarker
    • SimpleProgress
    • SmoothingETA
    • Timer
    • UnitProgress
    • Variable
  • Reference
    • ProgressBar
    • MultiBar
    • Parallel execution
    • progressbar CLI
    • Full module autodoc
      • progressbar.terminal package
        • progressbar.terminal.base module
        • progressbar.terminal.colors module
        • progressbar.terminal.stream module
      • progressbar.algorithms module
      • progressbar.bar module
      • progressbar.base module
      • progressbar.env module
      • progressbar.fast module
      • progressbar.multi module
      • progressbar.shortcuts module
      • progressbar.utils module
      • progressbar.widgets module
  • Explanation
    • Rendering and the update gate
    • Terminal detection
    • Performance and the fast path
    • Backwards compatibility

Project

  • Contributing
  • History
Back to top
View this page
Edit this page

Print while a bar is running¶

A plain print() call while a bar is redrawing collides with it on the same line – the two fight over the same carriage return, and neither comes out readable.

print() above the bar
"""Let `print()` calls show up above the bar instead of corrupting it.

Pass `redirect_stdout=True` and call `print()` as normal from inside the
loop -- the bar holds the line back and flushes it above the moving bar on
the next redraw, rather than the two colliding over the same carriage
return.
"""

import time

import progressbar

FILES = ['report.csv', 'errors.log', 'summary.json']
STEPS_PER_FILE = 8


def main() -> None:
    with progressbar.ProgressBar(
        max_value=len(FILES) * STEPS_PER_FILE,
        redirect_stdout=True,
    ) as bar:
        for index, filename in enumerate(FILES):
            print(f'Processing {filename}')
            for step in range(STEPS_PER_FILE):
                bar.update(index * STEPS_PER_FILE + step + 1)
                time.sleep(0.01)


if __name__ == '__main__':
    main()

Pass redirect_stdout=True and call print() normally from inside the loop. The bar holds the line back and flushes it above the moving bar on its next redraw. This only catches writes to sys.stdout: print() and anything else writing there directly. To route the stdlib logging module the same way, see Send logging output above a running bar.

Next
Send logging output above a running bar
Previous
Wrap an iterable without managing the bar yourself
Copyright © 2026, <a href="http://wol.ph/">Rick van Hattem (Wolph)</a>
Made with Sphinx and @pradyunsg's Furo