Open bstanden opened 6 years ago
Really good point! Especially useful on working on large iterators (using the generator iter()).
I think the easiest way to do something like this is to allow the user to pass a blocking factor to any Progress. This would change the operation of progress.next() so that self.index is always updated, but progress is only printed it this is the first call or if (self.index % self.bf) == 0. Similarly, this would also mean fewer calls to time.monotonic() and so on.
While time.perf_counter() is no longer a system call, I am not at all sure about time.monotonic(), since it is still supposed to be a time.
The calling convention could be to pass a block_size:
bar = Bar(max=result_count, block_size=4096)
For now, I am doing this above progress.Bar altogether as follows:
count += 1
if bar and (count % 4096)==0:
bar.next(4096)
Every call to update() causes the progress bar to produce output. If I'm using a Bar to track a loop of millions of iterations then my terminal is flooded with output even though the progress bar itself doesn't need to change.
Perhaps add an option lazy_write which, if true, causes writeln to remember what it last wrote - and if it's no different, it doesn't write anything to the terminal.