Skip to content

Commit

Permalink
fixed bug #154 "Progress bar display does not update"
Browse files Browse the repository at this point in the history
  • Loading branch information
wolph committed Feb 13, 2018
1 parent 2c82e37 commit e664f04
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions progressbar/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ def __init__(self, min_value=0, max_value=None, widgets=None,
self._iterable = None
self.custom_len = custom_len
self.init()
self._version = timeit.default_timer()

if poll_interval and isinstance(poll_interval, (int, float)):
poll_interval = timedelta(seconds=poll_interval)
Expand All @@ -280,6 +279,7 @@ def init(self):
self.updates = 0
self.end_time = None
self.extra = dict()
self._last_update = timeit.default_timer()

@property
def percentage(self):
Expand Down Expand Up @@ -518,7 +518,7 @@ def _needs_update(self):
'Returns whether the ProgressBar should redraw the line.'

if self.poll_interval:
delta = timeit.default_timer() - self._version
delta = timeit.default_timer() - self._last_update
poll_status = delta > self.poll_interval.total_seconds()
else:
poll_status = False
Expand All @@ -542,6 +542,12 @@ def update(self, value=None, force=False, **kwargs):
self.start()
return self.update(value, force=force, **kwargs)

minimum_update_interval = self._MINIMUM_UPDATE_INTERVAL
delta = timeit.default_timer() - self._last_update
if delta < minimum_update_interval and not force:
# Prevent updating too often
return

if value is not None and value is not base.UnknownLength:
if self.max_value is base.UnknownLength:
# Can't compare against unknown lengths so just update
Expand All @@ -556,16 +562,10 @@ def update(self, value=None, force=False, **kwargs):
else:
self.max_value = value

self._version = timeit.default_timer()
self._last_update = timeit.default_timer()
self.previous_value = self.value
self.value = value

minimum_update_interval = self._MINIMUM_UPDATE_INTERVAL
update_delta = timeit.default_timer() - self._version
if update_delta < minimum_update_interval and not force:
# Prevent updating too often
return

# Save the updated values for dynamic messages
for key in kwargs:
if key in self.dynamic_messages:
Expand Down Expand Up @@ -632,7 +632,7 @@ def start(self, max_value=None, init=True):
raise ValueError('Value out of range')

self.start_time = self.last_update_time = datetime.now()
self._version = timeit.default_timer()
self._last_update = timeit.default_timer()
self.update(self.min_value, force=True)

return self
Expand Down

0 comments on commit e664f04

Please sign in to comment.