mirror of
https://github.com/verigak/progress.git
synced 2025-12-11 12:43:01 +00:00
Now iter() calls finish even on an exception
As I reported in issue #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
This commit is contained in:
@@ -73,10 +73,12 @@ class Infinite(object):
|
||||
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):
|
||||
@@ -117,7 +119,9 @@ class Progress(Infinite):
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user