print_progress¶
-
menpo.visualize.
print_progress
(iterable, prefix='', n_items=None, offset=0)[source]¶ Print the remaining time needed to compute over an iterable.
To use, wrap an existing iterable with this function before processing in a for loop (see example).
The estimate of the remaining time is based on a moving average of the last 100 items completed in the loop.
Parameters: - iterable (iterable) – An iterable that will be processed. The iterable is passed through by this function, with the time taken for each complete iteration logged.
- prefix (str, optional) – If provided a string that will be prepended to the progress report at each level.
- n_items (int, optional) – Allows for
iterator
to be a generator whose length will be assumed to be n_items. If not provided, theniterator
needs to be Sizable. - offset (int, optional) – Useful in combination with
n_items
- report back the progress as if offset items have already been handled.n_items
will be left unchanged.
Raises: ValueError
–offset
provided withoutn_items
Examples
This for loop:
from time import sleep for i in print_progress(range(100)): sleep(1)
prints a progress report of the form:
[============= ] 70% (7/10) 00:00:03 remaining