From f2f47d5f90bcf6b908e165b40f4c8bfabcd1f149 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Mon, 22 Feb 2021 22:25:17 +0000 Subject: [PATCH 1/8] minor codacy fixes --- examples/7zx.py | 4 ++-- tests/tests_main.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/7zx.py b/examples/7zx.py index c5bc28b7e..edc5c95a1 100644 --- a/examples/7zx.py +++ b/examples/7zx.py @@ -77,11 +77,11 @@ def main(): unit="B", unit_scale=True) as tall: for fn, fcomp in zips.items(): md, sd = pty.openpty() - ex = subprocess.Popen( + ex = subprocess.Popen( # nosec cmd7zx + [fn], bufsize=1, stdout=md, # subprocess.PIPE, - stderr=subprocess.STDOUT) # nosec + stderr=subprocess.STDOUT) os.close(sd) with io.open(md, mode="rU", buffering=1) as m: with tqdm(total=sum(fcomp.values()), disable=len(zips) < 2, diff --git a/tests/tests_main.py b/tests/tests_main.py index aa477e5b5..564536244 100644 --- a/tests/tests_main.py +++ b/tests/tests_main.py @@ -36,9 +36,9 @@ def test_pipes(): """Test command line pipes""" ls_out = subprocess.check_output(['ls']) # nosec ls = subprocess.Popen(['ls'], stdout=subprocess.PIPE) # nosec - res = subprocess.Popen( + res = subprocess.Popen( # nosec [sys.executable, '-c', 'from tqdm.cli import main; main()'], - stdin=ls.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # nosec + stdin=ls.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = res.communicate() assert ls.poll() == 0 From b612be49ccecfe750e22c4c24bf01eedea7aab53 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Mon, 22 Feb 2021 22:27:58 +0000 Subject: [PATCH 2/8] tests: minify tox --- tox.ini | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/tox.ini b/tox.ini index 99a7c6dad..18f043e71 100644 --- a/tox.ini +++ b/tox.ini @@ -4,17 +4,11 @@ # and then run "tox" from this directory. [tox] -# deprecation warning: py{34} +# deprecation warning: py{27,py2,34,35} envlist=py{27,34,35,36,37,38,39,py2,py3}{,-tf}{,-keras}, perf, setup.py isolated_build=True -[coverage] -commands= - - coveralls - codecov -X pycov -e TOXENV - - codacy report -l Python -r coverage.xml --partial - -[extra] +[core] deps= pytest pytest-cov @@ -24,14 +18,14 @@ deps= coveralls codecov commands= - pytest --cov=tqdm --cov-report=xml --cov-report=term -k "not perf" - {[coverage]commands} -allowlist_externals=codacy + - coveralls + codecov -X pycov -e TOXENV + - codacy report -l Python -r coverage.xml --partial [testenv] -passenv=CI GITHUB_* TOXENV CODECOV_* COVERALLS_* CODACY_* HOME +passenv=TOXENV CI GITHUB_* CODECOV_* COVERALLS_* CODACY_* HOME deps= - {[extra]deps} + {[core]deps} cython matplotlib numpy @@ -39,17 +33,19 @@ deps= keras: keras py{36,37,38,39}: rich tf: tensorflow -commands={[extra]commands} -allowlist_externals={[extra]allowlist_externals} +commands= + pytest --cov=tqdm --cov-report=xml --cov-report=term -k "not perf" + {[core]commands} +allowlist_externals=codacy [testenv:py{27,py2}{,-tf}{,-keras}] commands= pytest --cov=tqdm --cov-report=xml --cov-report=term -k "not perf" -o addopts= -v --tb=short -rxs -W=error --durations=10 - {[coverage]commands} + {[core]commands} # no cython/numpy/pandas [testenv:py{34,py2,py3}] -deps={[extra]deps} +deps={[core]deps} [testenv:perf] deps= From bbf40d242b7af9cc6022726de709038e5f5f8061 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Mon, 22 Feb 2021 22:42:24 +0000 Subject: [PATCH 3/8] lint: fix some warnings --- benchmarks/benchmarks.py | 2 +- examples/include_no_requirements.py | 2 ++ tests/tests_main.py | 2 +- tqdm/_utils.py | 2 +- tqdm/notebook.py | 12 ++++++------ 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/benchmarks/benchmarks.py b/benchmarks/benchmarks.py index 5698600da..37f5df419 100644 --- a/benchmarks/benchmarks.py +++ b/benchmarks/benchmarks.py @@ -22,7 +22,7 @@ def __init__(self, length): def run(self, cls): pbar = cls(self.iterable) t0 = self.time() - [0 for _ in pbar] + [0 for _ in pbar] # pylint: disable=pointless-statement t1 = self.time() return t1 - t0 diff --git a/examples/include_no_requirements.py b/examples/include_no_requirements.py index 3682d8845..c51a85cb9 100644 --- a/examples/include_no_requirements.py +++ b/examples/include_no_requirements.py @@ -7,3 +7,5 @@ def tqdm(*args, **kwargs): if args: return args[0] return kwargs.get('iterable', None) + +__all__ = ['tqdm'] diff --git a/tests/tests_main.py b/tests/tests_main.py index 564536244..c02c896bb 100644 --- a/tests/tests_main.py +++ b/tests/tests_main.py @@ -61,7 +61,7 @@ def test_main_import(): sys.argv = ['', '--desc', 'Test CLI import', '--ascii', 'True', '--unit_scale', 'True'] try: - import tqdm.__main__ # NOQA + import tqdm.__main__ # NOQA, pylint: disable=unused-variable finally: sys.stdin, sys.argv = _SYS diff --git a/tqdm/_utils.py b/tqdm/_utils.py index 5bf54bb8c..2228691e2 100644 --- a/tqdm/_utils.py +++ b/tqdm/_utils.py @@ -1,7 +1,7 @@ from warnings import warn from .std import TqdmDeprecationWarning -from .utils import ( # NOQA +from .utils import ( # NOQA, pylint: disable=unused-import CUR_OS, IS_NIX, IS_WIN, RE_ANSI, Comparable, FormatReplace, SimpleTextIOWrapper, _basestring, _environ_cols_wrapper, _is_ascii, _is_utf, _range, _screen_shape_linux, _screen_shape_tput, _screen_shape_windows, _screen_shape_wrapper, _supports_unicode, diff --git a/tqdm/notebook.py b/tqdm/notebook.py index a1f6f8e1c..1e1431d89 100644 --- a/tqdm/notebook.py +++ b/tqdm/notebook.py @@ -248,9 +248,9 @@ def __init__(self, *args, **kwargs): if not self.disable: self.display() - def __iter__(self, *args, **kwargs): + def __iter__(self): try: - for obj in super(tqdm_notebook, self).__iter__(*args, **kwargs): + for obj in super(tqdm_notebook, self).__iter__(): # return super(tqdm...) will not catch exception yield obj # NB: except ... [ as ...] breaks IPython async KeyboardInterrupt @@ -260,9 +260,9 @@ def __iter__(self, *args, **kwargs): # NB: don't `finally: close()` # since this could be a shared bar which the user will `reset()` - def update(self, *args, **kwargs): + def update(self, n=1): try: - return super(tqdm_notebook, self).update(*args, **kwargs) + return super(tqdm_notebook, self).update(n=n) # NB: except ... [ as ...] breaks IPython async KeyboardInterrupt except: # NOQA # cannot catch KeyboardInterrupt when using manual tqdm @@ -272,8 +272,8 @@ def update(self, *args, **kwargs): # NB: don't `finally: close()` # since this could be a shared bar which the user will `reset()` - def close(self, *args, **kwargs): - super(tqdm_notebook, self).close(*args, **kwargs) + def close(self): + super(tqdm_notebook, self).close() # Try to detect if there was an error or KeyboardInterrupt # in manual mode: if n < total, things probably got wrong if self.total and self.n < self.total: From d710226d351e4b1b26c2397623b3ddea77cc13b1 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Thu, 25 Feb 2021 14:04:08 +0000 Subject: [PATCH 4/8] docs: add tidelift/security --- .github/FUNDING.yml | 1 + .github/ISSUE_TEMPLATE/config.yml | 4 ++-- .github/SECURITY.md | 14 ++++++++++++++ CONTRIBUTING.md | 5 ++--- 4 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 .github/SECURITY.md diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 44774f14e..0716fb69f 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,2 +1,3 @@ github: casperdcl custom: https://caspersci.uk.to/donate +tidelift: pypi/tqdm diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index c0e6a70a7..302456a1d 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,8 +1,8 @@ blank_issues_enabled: false contact_links: - - name: "FAQs and Known Issues" + - name: FAQs and Known Issues url: https://github.com/tqdm/tqdm/#faq-and-known-issues - about: "Frequently asked questions and known issues" + about: Frequently asked questions and known issues - name: "StackOverflow#tqdm" url: https://stackoverflow.com/questions/tagged/tqdm about: "Stack Overflow questions tagged #tqdm" diff --git a/.github/SECURITY.md b/.github/SECURITY.md new file mode 100644 index 000000000..9955d5fb8 --- /dev/null +++ b/.github/SECURITY.md @@ -0,0 +1,14 @@ +# Security Policy + +## Supported Versions + +| Version | Supported | +| ----------- | ------------------ | +| >= 4.11.2 | :white_check_mark: | +| < 4.11.2 | :x: | + +## Security contact information + +To report a security vulnerability, please use the +[Tidelift security contact](https://tidelift.com/security). +Tidelift will coordinate the fix and disclosure. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 568df615f..68796c0e7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -131,13 +131,12 @@ sanity-checking. The tqdm repository managers should: -- follow the [Semantic Versioning](https://semver.org/) convention +- follow the [Semantic Versioning](https://semver.org) convention - take care of this (instead of users) to avoid PR conflicts solely due to the version file bumping Note: tools can be used to automate this process, such as -[bumpversion](https://github.com/peritus/bumpversion) or -[python-semanticversion](https://github.com/rbarrois/python-semanticversion/). +[python-semanticversion](https://github.com/rbarrois/python-semanticversion). ## Checking setup.py From 90774d36a4c93030c94dfbbe83af0f4e09fbe031 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 7 Nov 2019 16:57:41 +0100 Subject: [PATCH 5/8] Allow hiding progressbar until some time interval has elapsed. This avoids printing the progressbar for very short loops. --- tests/tests_tqdm.py | 15 +++++++++++++++ tqdm/std.py | 41 ++++++++++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/tests/tests_tqdm.py b/tests/tests_tqdm.py index 56033fef9..5a744dd1c 100644 --- a/tests/tests_tqdm.py +++ b/tests/tests_tqdm.py @@ -622,6 +622,21 @@ def test_max_interval(): t2.close() +def test_waituntil(): + """Test waituntil""" + timer = DiscreteTimer() + with closing(StringIO()) as our_file: + t = tqdm(total=2, file=our_file, leave=True, waituntil=3) + cpu_timify(t, timer) + timer.sleep(2) + t.update(1) + assert not our_file.getvalue() + timer.sleep(2) + t.update(1) + assert our_file.getvalue() + t.close() + + def test_min_iters(): """Test miniters""" with closing(StringIO()) as our_file: diff --git a/tqdm/std.py b/tqdm/std.py index e73f4ab67..6cbfd6cfb 100644 --- a/tqdm/std.py +++ b/tqdm/std.py @@ -841,7 +841,7 @@ def wrapper(*args, **kwargs): def __init__(self, iterable=None, desc=None, total=None, leave=True, file=None, ncols=None, mininterval=0.1, maxinterval=10.0, miniters=None, - ascii=None, disable=False, unit='it', unit_scale=False, + waituntil=0.0, 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): @@ -890,6 +890,9 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True, file=None, 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#". @@ -1061,6 +1064,7 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True, file=None, self.maxinterval = maxinterval self.miniters = miniters self.dynamic_miniters = dynamic_miniters + self.waituntil = waituntil self.ascii = ascii self.disable = disable self.unit = unit @@ -1099,7 +1103,8 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True, file=None, if not gui: # Initialize the screen printer self.sp = self.status_printer(self.fp) - self.refresh(lock_args=self.lock_args) + if waituntil <= 0: + self.refresh(lock_args=self.lock_args) # Init the time counter self.last_print_t = self._time() @@ -1163,6 +1168,7 @@ def __iter__(self): mininterval = self.mininterval last_print_t = self.last_print_t last_print_n = self.last_print_n + start_t = self.start_t n = self.n time = self._time @@ -1174,8 +1180,9 @@ def __iter__(self): n += 1 if n - last_print_n >= self.miniters: - dt = time() - last_print_t - if dt >= mininterval: + cur_t = time() + dt = cur_t - last_print_t + if dt >= mininterval and cur_t - start_t >= self.waituntil: self.update(n - last_print_n) last_print_n = self.last_print_n last_print_t = self.last_print_t @@ -1218,8 +1225,10 @@ def update(self, n=1): # check counter first to reduce calls to time() if self.n - self.last_print_n >= self.miniters: - dt = self._time() - self.last_print_t - if dt >= self.mininterval: + cur_t = self._time() + dt = cur_t - self.last_print_t + 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: @@ -1279,15 +1288,17 @@ def fp_write(s): leave = pos == 0 if self.leave is None else self.leave with self._lock: - 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 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') def clear(self, nolock=False): """Clear current bar display.""" From caf6dbbaae721f94009846f5bdd8bd1431cdde28 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 24 Mar 2020 21:34:20 +0000 Subject: [PATCH 6/8] performance/optimisation and slight tidy --- tqdm/std.py | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/tqdm/std.py b/tqdm/std.py index 6cbfd6cfb..4730c9153 100644 --- a/tqdm/std.py +++ b/tqdm/std.py @@ -841,10 +841,11 @@ def wrapper(*args, **kwargs): 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 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True, file=None, 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 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True, file=None, 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 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True, file=None, 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 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True, file=None, 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 @@ def __iter__(self): 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 @@ def __iter__(self): 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 @@ def update(self, n=1): 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 @@ def fp_write(s): 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.""" From 90cb341e8eba094042237e6c65a8754066c174ce Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Thu, 25 Feb 2021 16:08:12 +0000 Subject: [PATCH 7/8] rename `waituntil` => `delay` --- tests/tests_tqdm.py | 6 +++--- tqdm/std.py | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/tests_tqdm.py b/tests/tests_tqdm.py index 5a744dd1c..8cf006533 100644 --- a/tests/tests_tqdm.py +++ b/tests/tests_tqdm.py @@ -622,11 +622,11 @@ def test_max_interval(): t2.close() -def test_waituntil(): - """Test waituntil""" +def test_delay(): + """Test delay""" timer = DiscreteTimer() with closing(StringIO()) as our_file: - t = tqdm(total=2, file=our_file, leave=True, waituntil=3) + t = tqdm(total=2, file=our_file, leave=True, delay=3) cpu_timify(t, timer) timer.sleep(2) t.update(1) diff --git a/tqdm/std.py b/tqdm/std.py index 4730c9153..bc5e71ecd 100644 --- a/tqdm/std.py +++ b/tqdm/std.py @@ -844,7 +844,7 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True, file=None, 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, waituntil=0, gui=False, + lock_args=None, nrows=None, colour=None, delay=0, gui=False, **kwargs): """ Parameters @@ -952,7 +952,7 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True, file=None, The fallback is 20. colour : str, optional Bar colour (e.g. 'green', '#00ff00'). - waituntil : float, optional + delay : float, optional Don't display until [default: 0] seconds have elapsed. gui : bool, optional WARNING: internal parameter - do not use. @@ -1071,7 +1071,7 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True, file=None, self.unit_divisor = unit_divisor self.initial = initial self.lock_args = lock_args - self.waituntil = waituntil + self.delay = delay self.gui = gui self.dynamic_ncols = dynamic_ncols self.smoothing = smoothing @@ -1103,7 +1103,7 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True, file=None, if not gui: # Initialize the screen printer self.sp = self.status_printer(self.fp) - if waituntil <= 0: + if delay <= 0: self.refresh(lock_args=self.lock_args) # Init the time counter @@ -1168,7 +1168,7 @@ def __iter__(self): mininterval = self.mininterval last_print_t = self.last_print_t last_print_n = self.last_print_n - min_start_t = self.start_t + self.waituntil + min_start_t = self.start_t + self.delay n = self.n time = self._time @@ -1227,7 +1227,7 @@ def update(self, n=1): 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.delay: cur_t = self._time() dn = self.n - self.last_print_n # >= n if self.smoothing and dt and dn: @@ -1287,7 +1287,7 @@ def fp_write(s): leave = pos == 0 if self.leave is None else self.leave with self._lock: - if self.last_print_t < self.start_t + self.waituntil: + if self.last_print_t < self.start_t + self.delay: # haven't ever displayed; nothing to clear return if leave: From 47e303cdeef590c1477e6f6b3cc41b97aa077153 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Thu, 25 Feb 2021 16:25:05 +0000 Subject: [PATCH 8/8] minor `close()` optimisation --- tqdm/std.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tqdm/std.py b/tqdm/std.py index bc5e71ecd..d25ab281d 100644 --- a/tqdm/std.py +++ b/tqdm/std.py @@ -1269,6 +1269,10 @@ def close(self): pos = abs(self.pos) self._decr_instances(self) + if self.last_print_t < self.start_t + self.delay: + # haven't ever displayed; nothing to clear + return + # GUI mode if getattr(self, 'sp', None) is None: return @@ -1287,9 +1291,6 @@ def fp_write(s): leave = pos == 0 if self.leave is None else self.leave with self._lock: - if self.last_print_t < self.start_t + self.delay: - # haven't ever displayed; nothing to clear - return if leave: # stats for overall rate (no weighted average) self._ema_dt = lambda: None