code: def dodging(bar):
          
          class ShyProgressBar(object):
              """Context manager that implements a progress bar that gets out of the way"""
  
              def __enter__(self):
                  """Erase the progress bar so bits of disembodied progress bar don't get scrolled up the terminal."""
                  # My terminal has no status line, so we make one manually.
                  bar._is_dodging += 1  # Increment before calling erase(), which
                                        # calls dodging() again.
                  if bar._is_dodging <= 1:  # It *was* 0.
                      bar.erase()
  
              def __exit__(self, type, value, tb):
                  """Redraw the last saved state of the progress bar."""
                  if bar._is_dodging == 1:  # Can't decrement yet; write() could
                                            # read it.
                      # This is really necessary only because we monkeypatch
                      # stderr; the next test is about to start and will redraw
                      # the bar.
                      with bar._at_last_line():
                          bar.stream.write(bar.last)
                      bar.stream.flush()
                  bar._is_dodging -= 1
  
          return ShyProgressBar()
docs: Return a context manager which erases the bar, lets you output things, and then redraws the bar.
  
          It's reentrant.