astro py:docs

- Index
- Modules

### Navigation

- next »
- « previous |
- Astropy v1.1.1 »
- Astropy Core Package Utilities (`astropy.utils`) »
- ProgressBar

# ProgressBar

class `astropy.utils.console.``ProgressBar`(total_or_items, ipython_widget=False, file=None)

  Bases: `astropy.extern.six.Iterator`

  A class to display a progress bar in the terminal.

  It is designed to be used either with the `with` statement:

      with ProgressBar(len(items)) as bar:
          for item in enumerate(items):
              bar.update()

  or as a generator:

      for item in ProgressBar(items):
          item.process()

  Parameters:

  total_or_items : int or sequence

  > If an int, the number of increments in the process being tracked. If a sequence, the items to iterate over.

  ipython_widget : bool, optional

  > If `True`, the progress bar will display as an IPython notebook widget.

  file : writable file-like object, optional

  > The file to write the progress bar to. Defaults to `sys.stdout`. If `file` is not a tty (as determined by calling its `isatty` member, if any, or special case hacks to detect the IPython console), the progress bar will be completely silent.

  Methods Summary

  `map`(function, items[, multiprocess, file, step]) | Does a `map` operation while displaying a progress bar with percentage complete.
  `update`([value]) | Update progress bar via the console or notebook accordingly.

  Methods Documentation

  classmethod `map`(function, items, multiprocess=False, file=None, step=100)

    Does a `map` operation while displaying a progress bar with percentage complete.

        def work(i):
            print(i)

        ProgressBar.map(work, range(50))

    Parameters:

    function : function

    > Function to call for each step

    items : sequence

    > Sequence where each element is a tuple of arguments to pass to function.

    multiprocess : bool, optional

    > If `True`, use the `multiprocessing` module to distribute each task to a different processor core.

    file : writeable file-like object, optional

    > The file to write the progress bar to. Defaults to `sys.stdout`. If `file` is not a tty (as determined by calling its `isatty` member, if any), the scrollbar will be completely silent.

    step : int, optional

    > Update the progress bar at least every step steps (default: 100). If `multiprocess` is `True`, this will affect the size of the chunks of `items` that are submitted as separate tasks to the process pool. A large step size may make the job complete faster if `items` is very long.

  `update`(value=None)

    Update progress bar via the console or notebook accordingly.