def progressbar(iterable, desc='', total=None, file=sys.stderr,
                mininterval=0.05, miniters=1, init_interval=1.):
    """ Get an iterable object, and return an iterator which acts
    exactly like the iterable, but prints a progress meter and updates
    it every time a value is requested.

    Parameters
    ----------
    desc : str
        Can contain a short string, describing the progress,
        that is added in the beginning of the line.
    total : int
        Can give the number of expected iterations. If not given,
        len(iterable) is used if it is defined.
    file : object
        Can be a file-like object to output the progress message to.
    mininterval : float
        Defaults to ``0.05``.
    miniters : int
        If less than mininterval seconds or miniters
        iterations have passed since the last progress meter
        update, it is not updated again. Defaults to ``1``.
    init_interval : float
        Defaults to ``1``.
    """
    if total is None:
        try:
            total = len(iterable)
        except TypeError:
            total = None

    prefix = desc + ': ' if desc else ''

    printer = StatusPrinter(file)
    status = prefix + format_meter(0, total, 0)

    timer = threading.Timer(init_interval, printer.write, args=[status])
    timer.start()

    start_time = last_print_time = time.time()
    last_print_n = 0
    n = 0

    try:
        for obj in iterable:
            error = (yield)
            yield obj
            timer.cancel()

            # Now the object was created and processed, so we
            # can print the meter.
            n += 1
            if n - last_print_n >= miniters:
                # We check the counter first, to reduce the
                # overhead of time.time()
                current_time = time.time()

                if (current_time - last_print_time) >= mininterval:
                    time_delta = current_time - start_time
                    formated_str = format_meter(n, total, time_delta, error)
                    printer.write(prefix + formated_str)
                    last_print_n = n
                    last_print_time = current_time
    finally:
        # in case of instant error or early interuption
        timer.cancel()
        printer.clean()
dataset/ETHPy150Open itdxer/neupy/neupy/helpers/progressbar.py/progressbar/original