rasbt / pyprind

PyPrind - Python Progress Indicator Utility
BSD 3-Clause "New" or "Revised" License
547 stars 65 forks source link

Update ETA more frequently than the bar #22

Closed kvdb closed 8 years ago

kvdb commented 8 years ago

The following example shows a default progress bar that takes a long time to complete. The problem is that the ETA value is only updated when the progress bar advances:

import pyprind
import time
amount = 80000
bar = pyprind.ProgBar(amount, width=10)
for i in enumerate(range(amount)):
  time.sleep(.1) # some op
  bar.update()

I'd like a more frequent ETA update. I'm interested less in the bar graph. To work around this, I can set bar width to 1000, this redraws the bar more often and thus gives me a usable ETA calculation too.

Perhaps the redrawing frequency of the bar and ETA can be decoupled?

rasbt commented 8 years ago

Thanks for the feedback. That's a good point, currently, the output is only generated if the progress bar would advance by one symbol (e.g., '#'), but this can be annoying if you are running along task and want to get the ETA estimates more frequently. I will take a look at it and add a param to flush the bar more frequently.

I am thinking of 2 ideas here

1) an additional parameter in the .update() method to force the bar to be printed

e.g.,

import pyprind
import time
amount = 80000
bar = pyprind.ProgBar(amount, width=10)
for i in enumerate(range(amount)):
  time.sleep(.1) # some op
  bar.update(force_flush=True)

and an "update interval" in seconds for the progbar itself

bar = ProgBar(100, update_interval='auto')

vs

bar = ProgBar(100, update_interval=5) # every 5 seconds
rasbt commented 8 years ago

I just added the force_flush parameter to the update method, and the ProgBar and ProgPercent objects got a update_interval parameter which let's you specify the update intervals now.

kvdb commented 8 years ago

That's fast! Will try it out tomorrow, thanks!