performance/optimisation and slight tidy

This commit is contained in:
Casper da Costa-Luis 2020-03-24 21:34:20 +00:00
parent 90774d36a4
commit caf6dbbaae
No known key found for this signature in database
GPG Key ID: 986B408043AE090D
1 changed files with 21 additions and 21 deletions

View File

@ -841,10 +841,11 @@ class tqdm(Comparable):
def __init__(self, iterable=None, desc=None, total=None, leave=True, file=None,
ncols=None, mininterval=0.1, maxinterval=10.0, miniters=None,
waituntil=0.0, ascii=None, disable=False, unit='it', unit_scale=False,
ascii=None, disable=False, unit='it', unit_scale=False,
dynamic_ncols=False, smoothing=0.3, bar_format=None, initial=0,
position=None, postfix=None, unit_divisor=1000, write_bytes=None,
lock_args=None, nrows=None, colour=None, gui=False, **kwargs):
lock_args=None, nrows=None, colour=None, waituntil=0, gui=False,
**kwargs):
"""
Parameters
----------
@ -890,9 +891,6 @@ class tqdm(Comparable):
Tweak this and `mininterval` to get very efficient loops.
If your progress is erratic with both fast and slow iterations
(network, skipping items, etc) you should set miniters=1.
waituntil : float, optional
Don't display the progressbar until this number [default: 0] of
seconds has elapsed.
ascii : bool or str, optional
If unspecified or False, use unicode (smooth blocks) to fill
the meter. The fallback is to use ASCII characters " 123456789#".
@ -954,6 +952,8 @@ class tqdm(Comparable):
The fallback is 20.
colour : str, optional
Bar colour (e.g. 'green', '#00ff00').
waituntil : float, optional
Don't display until [default: 0] seconds have elapsed.
gui : bool, optional
WARNING: internal parameter - do not use.
Use tqdm.gui.tqdm(...) instead. If set, will attempt to use
@ -1064,7 +1064,6 @@ class tqdm(Comparable):
self.maxinterval = maxinterval
self.miniters = miniters
self.dynamic_miniters = dynamic_miniters
self.waituntil = waituntil
self.ascii = ascii
self.disable = disable
self.unit = unit
@ -1072,6 +1071,7 @@ class tqdm(Comparable):
self.unit_divisor = unit_divisor
self.initial = initial
self.lock_args = lock_args
self.waituntil = waituntil
self.gui = gui
self.dynamic_ncols = dynamic_ncols
self.smoothing = smoothing
@ -1168,7 +1168,7 @@ class tqdm(Comparable):
mininterval = self.mininterval
last_print_t = self.last_print_t
last_print_n = self.last_print_n
start_t = self.start_t
min_start_t = self.start_t + self.waituntil
n = self.n
time = self._time
@ -1182,7 +1182,7 @@ class tqdm(Comparable):
if n - last_print_n >= self.miniters:
cur_t = time()
dt = cur_t - last_print_t
if dt >= mininterval and cur_t - start_t >= self.waituntil:
if dt >= mininterval and cur_t >= min_start_t:
self.update(n - last_print_n)
last_print_n = self.last_print_n
last_print_t = self.last_print_t
@ -1227,8 +1227,7 @@ class tqdm(Comparable):
if self.n - self.last_print_n >= self.miniters:
cur_t = self._time()
dt = cur_t - self.last_print_t
if (dt >= self.mininterval
and cur_t - self.start_t >= self.waituntil):
if dt >= self.mininterval and cur_t >= self.start_t + self.waituntil:
cur_t = self._time()
dn = self.n - self.last_print_n # >= n
if self.smoothing and dt and dn:
@ -1288,17 +1287,18 @@ class tqdm(Comparable):
leave = pos == 0 if self.leave is None else self.leave
with self._lock:
# If the following doesn't hold, we haven't even printed anything.
if self.last_print_t - self.start_t >= self.waituntil:
if leave:
# stats for overall rate (no weighted average)
self._ema_dt = lambda: None
self.display(pos=0)
fp_write('\n')
else:
# clear previous display
if self.display(msg='', pos=pos) and not pos:
fp_write('\r')
if self.last_print_t < self.start_t + self.waituntil:
# haven't ever displayed; nothing to clear
return
if leave:
# stats for overall rate (no weighted average)
self._ema_dt = lambda: None
self.display(pos=0)
fp_write('\n')
else:
# clear previous display
if self.display(msg='', pos=pos) and not pos:
fp_write('\r')
def clear(self, nolock=False):
"""Clear current bar display."""