diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-02 08:25:08 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-02 08:25:08 +0000 |
commit | d7f67a741417e84c1106ff7f7d35d0968f56aba4 (patch) | |
tree | 27ee221971a079ec58aa5b67852015bee61751d6 /examples | |
parent | Adding debian version 4.64.1-4. (diff) | |
download | tqdm-d7f67a741417e84c1106ff7f7d35d0968f56aba4.tar.xz tqdm-d7f67a741417e84c1106ff7f7d35d0968f56aba4.zip |
Merging upstream version 4.66.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/7zx.py | 2 | ||||
-rw-r--r-- | examples/async_coroutines.py | 4 | ||||
-rw-r--r-- | examples/parallel_bars.py | 18 | ||||
-rw-r--r-- | examples/redirect_print.py | 2 | ||||
-rw-r--r-- | examples/simple_examples.py | 7 | ||||
-rw-r--r-- | examples/tqdm_wget.py | 5 |
6 files changed, 10 insertions, 28 deletions
diff --git a/examples/7zx.py b/examples/7zx.py index 3d15254..18d7e33 100644 --- a/examples/7zx.py +++ b/examples/7zx.py @@ -18,8 +18,6 @@ Options: NOTSET -d, --debug-trace Print lots of debugging information (-D NOTSET) """ -from __future__ import print_function - import io import logging import os diff --git a/examples/async_coroutines.py b/examples/async_coroutines.py index 40f4f24..3e31905 100644 --- a/examples/async_coroutines.py +++ b/examples/async_coroutines.py @@ -1,6 +1,4 @@ -""" -Asynchronous examples using `asyncio`, `async` and `await` on `python>=3.7`. -""" +"""Asynchronous examples using `asyncio`, `async` and `await`.""" import asyncio from tqdm.asyncio import tqdm, trange diff --git a/examples/parallel_bars.py b/examples/parallel_bars.py index 498fd61..b7e1494 100644 --- a/examples/parallel_bars.py +++ b/examples/parallel_bars.py @@ -1,6 +1,3 @@ -from __future__ import print_function - -import sys from concurrent.futures import ThreadPoolExecutor from functools import partial from multiprocessing import Pool, RLock, freeze_support @@ -12,21 +9,19 @@ from tqdm.auto import tqdm, trange from tqdm.contrib.concurrent import process_map, thread_map NUM_SUBITERS = 9 -PY2 = sys.version_info[:1] <= (2,) def progresser(n, auto_position=True, write_safe=False, blocking=True, progress=False): interval = random() * 0.002 / (NUM_SUBITERS - n + 2) # nosec total = 5000 - text = "#{0}, est. {1:<04.2}s".format(n, interval * total) + text = f"#{n}, est. {interval * total:<04.2g}s" for _ in trange(total, desc=text, disable=not progress, lock_args=None if blocking else (False,), position=None if auto_position else n): sleep(interval) # NB: may not clear instances with higher `position` upon completion # since this worker may not know about other bars #796 - if write_safe: - # we think we know about other bars (currently only py3 threading) + if write_safe: # we think we know about other bars if n == 6: tqdm.write("n == 6 completed") return n + 1 @@ -37,7 +32,7 @@ if __name__ == '__main__': L = list(range(NUM_SUBITERS))[::-1] print("Simple thread mapping") - thread_map(partial(progresser, write_safe=not PY2), L, max_workers=4) + thread_map(partial(progresser, write_safe=True), L, max_workers=4) print("Simple process mapping") process_map(partial(progresser), L, max_workers=4) @@ -54,8 +49,5 @@ if __name__ == '__main__': print("Multi-threading") tqdm.set_lock(TRLock()) - pool_args = {} - if not PY2: - pool_args.update(initializer=tqdm.set_lock, initargs=(tqdm.get_lock(),)) - with ThreadPoolExecutor(**pool_args) as p: - p.map(partial(progresser, progress=True, write_safe=not PY2, blocking=False), L) + with ThreadPoolExecutor(initializer=tqdm.set_lock, initargs=(tqdm.get_lock(),)) as p: + p.map(partial(progresser, progress=True, write_safe=True, blocking=False), L) diff --git a/examples/redirect_print.py b/examples/redirect_print.py index 0f9721e..38e6b4f 100644 --- a/examples/redirect_print.py +++ b/examples/redirect_print.py @@ -10,8 +10,6 @@ any input string to `tqdm.write()`, and supply the arguments A reusable canonical example is given below: """ -from __future__ import print_function - import contextlib import sys from time import sleep diff --git a/examples/simple_examples.py b/examples/simple_examples.py index f3401d3..bff1c9e 100644 --- a/examples/simple_examples.py +++ b/examples/simple_examples.py @@ -2,7 +2,7 @@ # Simple tqdm examples and profiling # Benchmark -for i in _range(int(1e8)): +for i in range(int(1e8)): pass # Basic demo @@ -33,7 +33,7 @@ try: except ImportError: pass else: - for i in ProgressBar()(_range(int(1e8))): + for i in ProgressBar()(range(int(1e8))): pass # Dynamic miniters benchmark @@ -61,5 +61,4 @@ for _ in trange(16, leave=True): stmts = filter(None, re.split(r'\n\s*#.*?\n', __doc__)) for s in stmts: print(s.replace('import tqdm\n', '')) - print(timeit(stmt='try:\n\t_range = xrange' - '\nexcept:\n\t_range = range\n' + s, number=1), 'seconds') + print(timeit(stmt=s, number=1), 'seconds') diff --git a/examples/tqdm_wget.py b/examples/tqdm_wget.py index 8663e5a..ee8b9f3 100644 --- a/examples/tqdm_wget.py +++ b/examples/tqdm_wget.py @@ -20,11 +20,8 @@ Options: The local file path in which to save the url [default: /dev/null]. """ -try: - from urllib import request as urllib -except ImportError: # py2 - import urllib from os import devnull +from urllib import request as urllib from docopt import docopt |