ProgressBar¶
Progress Bar utility for tasks with a known size limit
Functions¶
-
ProgressBar.
__init__
(self, progress_format, total_work, num_spaces, use_bar=False, time_format=None, refresh_interval=1)¶ Configures the newly built progress bar instance
Parameters: - progress_format – (str): format string (work done, total work, percentage) to be used for the printed message
- total_work – (int): total amount of work to be done (in some measuring unit)
- num_spaces – (int): number of spaces that should be used before the format message is printed
- use_bar – (bool, optional): True iff should also print a graphical status bar (False by default)
- time_format – (str, optional) : time format to be used for the elapsed time (None by default)
- refresh_interval – (int, optional): time period (in seconds) used to update the shown status, or -1 if not activated. (1 by default)
-
ProgressBar.
start
(self)¶ Marks the start of the progress bar
-
ProgressBar.
advance
(self, units, force_print=False)¶ Marks the completion of X units of work
Parameters: - units – (int): Number of units of work that were finished
- force_print – (bool, optional): True iff should force an update of the printed message (False by default)
-
ProgressBar.
update
(self, force_print=False)¶ An update attempt to the shown progress status
Parameters: force_print – (bool, optional): True iff should force an update of the printed message (False by default)
-
ProgressBar.
printProgress
(self)¶ Prints the progress status + progress bar
-
ProgressBar.
finish
(self)¶ Close the progress bar (on error / successful finish)
Usage Examples¶
- Creating a classic progress bar that advances randomly:
p = ProgressBar('Leaked %3d / %3d bytes - %3d%% Completed', 250, 30, True, time_format="Elapsed %M:%S -") p.start() p.advance(1) time.sleep(2) p.advance(50) time.sleep(1.5) p.advance(100) time.sleep(2) p.advance(1) time.sleep(0.5) p.advance(200) p.finish()