Skip to content

Commit

Permalink
Now iter() calls finish even on an exception
Browse files Browse the repository at this point in the history
As I reported in issue verigak#14 raising an exception in a loop over a
iterator got from a iter() call will not finalize the bar.

This commit uses a try, finally block to ensure that finish is always
called
  • Loading branch information
sindreij committed Dec 10, 2014
1 parent 723024a commit 94ff8dd
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions progress/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ def next(self, n=1):
self.update()

def iter(self, it):
for x in it:
yield x
self.next()
self.finish()
try:
for x in it:
yield x
self.next()
finally:
self.finish()


class Progress(Infinite):
Expand Down Expand Up @@ -117,7 +119,9 @@ def iter(self, it):
except TypeError:
pass

for x in it:
yield x
self.next()
self.finish()
try:
for x in it:
yield x
self.next()
finally:
self.finish()

0 comments on commit 94ff8dd

Please sign in to comment.