ethanfu / python-progressbar

Automatically exported from code.google.com/p/python-progressbar
Other
0 stars 0 forks source link

ETA() does not update to Time upon finishing #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The ETA() is supposed to switch to total time spent after the ProgressBar() is 
finished. However, this does not happen because there is no update of the text. 
(Similarly, the RotatingMarker() should go to | but this too is not updated.)

The reason for the lack of update is that _need_update() returns
         return self.currval >= self.next_update
whereas it should be:
         return self.currval >= self.next_update or self.finished

*** What is the expected output? What do you see instead? ***

Using the following code:
x = []
for y in withProgress(range(10**6), 
pbar=StandardProgressBar(title='squaring...')):
    x.append(y**2)

The output is:
squaring...\ 100% |=============================================| ETA:  00:00:00

The expected output (obtained with the above fix) is:

squaring...| 100% |=============================================| Time: 00:00:04

*** What version of the product are you using? On what operating system? ***
Python 2.7, progressbar 2.3-dev, Mac OSX and Linux (Fedora Core 12)

Original issue reported on code.google.com by jni.s...@gmail.com on 18 Apr 2011 at 9:11

GoogleCodeExporter commented 9 years ago
I believe you're correct, but I can't reproduce it. What's the implementation 
of withProgress? Are you using the progressbar as an iterator like in example7: 
http://code.google.com/p/python-progressbar/source/browse/progressbar/examples.p
y#84 ?

>>> from progressbar import *
>>> pbar = ProgressBar(widgets=[Percentage(), ' ', Bar(), ' ', ETA()])
>>> for i in pbar(range(10**6)):
...     pass
... 
100% |##################################################| Time: 0:00:06

Original comment by nilton.v...@gmail.com on 19 Apr 2011 at 3:56

GoogleCodeExporter commented 9 years ago
Ha, I didn't realize ProgressBar had that capability. =) I reimplemented the
iterator idea myself. But I have the same issue with slightly modified
example7() code:

def example7():
     widgets = [RotatingMarker(), ' ', Percentage(), ' ', Bar(), ' ', ETA()]
     pbar=ProgressBar(widgets=widgets)
     x = []
     for i in pbar(range(10**6)):
         x.append(i**2)
     return x

x = example7()
\ 100% |########################################################| ETA:
 00:00:00

Adding the "or self.finished":

x = example7()
| 100% |########################################################| Time:
00:00:02

Can you reproduce it with that exact code?

Original comment by jni.s...@gmail.com on 19 Apr 2011 at 4:08

GoogleCodeExporter commented 9 years ago
Looking at self._next_update(), maybe it has something to do with 
machine-dependent floating point errors?

Original comment by jni.s...@gmail.com on 19 Apr 2011 at 4:12

GoogleCodeExporter commented 9 years ago
Somehow that still works for me. It might indeed be some machine-dependent 
floating point error. But I could reproduce with this:

def repro():
  pbar = ProgressBar(maxval=10**6, widgets=[Percentage(), ' ', Bar(), ' ', ETA()]).start()
  pbar.update(10**6 - 1)
  pbar.update(10**6)
  pbar.finish()

I'm submitting the fix you suggested.

Original comment by nilton.v...@gmail.com on 19 Apr 2011 at 4:25

GoogleCodeExporter commented 9 years ago
Done: 
http://code.google.com/p/python-progressbar/source/detail?r=cb58b5d2c7669d8218ae
3b5966fc7e1389ed1d9b

Thanks for reporting!

Original comment by nilton.v...@gmail.com on 19 Apr 2011 at 4:28

GoogleCodeExporter commented 9 years ago
Thanks for the fast response! =)

Original comment by jni.s...@gmail.com on 19 Apr 2011 at 4:44