mirror of https://github.com/tqdm/tqdm.git
performance/optimisation and slight tidy
This commit is contained in:
parent
90774d36a4
commit
caf6dbbaae
42
tqdm/std.py
42
tqdm/std.py
|
@ -841,10 +841,11 @@ class tqdm(Comparable):
|
||||||
|
|
||||||
def __init__(self, iterable=None, desc=None, total=None, leave=True, file=None,
|
def __init__(self, iterable=None, desc=None, total=None, leave=True, file=None,
|
||||||
ncols=None, mininterval=0.1, maxinterval=10.0, miniters=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,
|
dynamic_ncols=False, smoothing=0.3, bar_format=None, initial=0,
|
||||||
position=None, postfix=None, unit_divisor=1000, write_bytes=None,
|
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
|
Parameters
|
||||||
----------
|
----------
|
||||||
|
@ -890,9 +891,6 @@ class tqdm(Comparable):
|
||||||
Tweak this and `mininterval` to get very efficient loops.
|
Tweak this and `mininterval` to get very efficient loops.
|
||||||
If your progress is erratic with both fast and slow iterations
|
If your progress is erratic with both fast and slow iterations
|
||||||
(network, skipping items, etc) you should set miniters=1.
|
(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
|
ascii : bool or str, optional
|
||||||
If unspecified or False, use unicode (smooth blocks) to fill
|
If unspecified or False, use unicode (smooth blocks) to fill
|
||||||
the meter. The fallback is to use ASCII characters " 123456789#".
|
the meter. The fallback is to use ASCII characters " 123456789#".
|
||||||
|
@ -954,6 +952,8 @@ class tqdm(Comparable):
|
||||||
The fallback is 20.
|
The fallback is 20.
|
||||||
colour : str, optional
|
colour : str, optional
|
||||||
Bar colour (e.g. 'green', '#00ff00').
|
Bar colour (e.g. 'green', '#00ff00').
|
||||||
|
waituntil : float, optional
|
||||||
|
Don't display until [default: 0] seconds have elapsed.
|
||||||
gui : bool, optional
|
gui : bool, optional
|
||||||
WARNING: internal parameter - do not use.
|
WARNING: internal parameter - do not use.
|
||||||
Use tqdm.gui.tqdm(...) instead. If set, will attempt to use
|
Use tqdm.gui.tqdm(...) instead. If set, will attempt to use
|
||||||
|
@ -1064,7 +1064,6 @@ class tqdm(Comparable):
|
||||||
self.maxinterval = maxinterval
|
self.maxinterval = maxinterval
|
||||||
self.miniters = miniters
|
self.miniters = miniters
|
||||||
self.dynamic_miniters = dynamic_miniters
|
self.dynamic_miniters = dynamic_miniters
|
||||||
self.waituntil = waituntil
|
|
||||||
self.ascii = ascii
|
self.ascii = ascii
|
||||||
self.disable = disable
|
self.disable = disable
|
||||||
self.unit = unit
|
self.unit = unit
|
||||||
|
@ -1072,6 +1071,7 @@ class tqdm(Comparable):
|
||||||
self.unit_divisor = unit_divisor
|
self.unit_divisor = unit_divisor
|
||||||
self.initial = initial
|
self.initial = initial
|
||||||
self.lock_args = lock_args
|
self.lock_args = lock_args
|
||||||
|
self.waituntil = waituntil
|
||||||
self.gui = gui
|
self.gui = gui
|
||||||
self.dynamic_ncols = dynamic_ncols
|
self.dynamic_ncols = dynamic_ncols
|
||||||
self.smoothing = smoothing
|
self.smoothing = smoothing
|
||||||
|
@ -1168,7 +1168,7 @@ class tqdm(Comparable):
|
||||||
mininterval = self.mininterval
|
mininterval = self.mininterval
|
||||||
last_print_t = self.last_print_t
|
last_print_t = self.last_print_t
|
||||||
last_print_n = self.last_print_n
|
last_print_n = self.last_print_n
|
||||||
start_t = self.start_t
|
min_start_t = self.start_t + self.waituntil
|
||||||
n = self.n
|
n = self.n
|
||||||
time = self._time
|
time = self._time
|
||||||
|
|
||||||
|
@ -1182,7 +1182,7 @@ class tqdm(Comparable):
|
||||||
if n - last_print_n >= self.miniters:
|
if n - last_print_n >= self.miniters:
|
||||||
cur_t = time()
|
cur_t = time()
|
||||||
dt = cur_t - last_print_t
|
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)
|
self.update(n - last_print_n)
|
||||||
last_print_n = self.last_print_n
|
last_print_n = self.last_print_n
|
||||||
last_print_t = self.last_print_t
|
last_print_t = self.last_print_t
|
||||||
|
@ -1227,8 +1227,7 @@ class tqdm(Comparable):
|
||||||
if self.n - self.last_print_n >= self.miniters:
|
if self.n - self.last_print_n >= self.miniters:
|
||||||
cur_t = self._time()
|
cur_t = self._time()
|
||||||
dt = cur_t - self.last_print_t
|
dt = cur_t - self.last_print_t
|
||||||
if (dt >= self.mininterval
|
if dt >= self.mininterval and cur_t >= self.start_t + self.waituntil:
|
||||||
and cur_t - self.start_t >= self.waituntil):
|
|
||||||
cur_t = self._time()
|
cur_t = self._time()
|
||||||
dn = self.n - self.last_print_n # >= n
|
dn = self.n - self.last_print_n # >= n
|
||||||
if self.smoothing and dt and dn:
|
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
|
leave = pos == 0 if self.leave is None else self.leave
|
||||||
|
|
||||||
with self._lock:
|
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 self.last_print_t - self.start_t >= self.waituntil:
|
# haven't ever displayed; nothing to clear
|
||||||
if leave:
|
return
|
||||||
# stats for overall rate (no weighted average)
|
if leave:
|
||||||
self._ema_dt = lambda: None
|
# stats for overall rate (no weighted average)
|
||||||
self.display(pos=0)
|
self._ema_dt = lambda: None
|
||||||
fp_write('\n')
|
self.display(pos=0)
|
||||||
else:
|
fp_write('\n')
|
||||||
# clear previous display
|
else:
|
||||||
if self.display(msg='', pos=pos) and not pos:
|
# clear previous display
|
||||||
fp_write('\r')
|
if self.display(msg='', pos=pos) and not pos:
|
||||||
|
fp_write('\r')
|
||||||
|
|
||||||
def clear(self, nolock=False):
|
def clear(self, nolock=False):
|
||||||
"""Clear current bar display."""
|
"""Clear current bar display."""
|
||||||
|
|
Loading…
Reference in New Issue