Skip to content

Use progress bar in tqdm #264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions ipyparallel/client/asyncresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
from Queue import Queue

from decorator import decorator
import tqdm
import zmq
from zmq import MessageTracker

from IPython import get_ipython
from IPython.core.display import clear_output, display, display_pretty
from IPython.core.display import display, display_pretty
from ipyparallel import error
from ipyparallel.util import utcnow, compare_datetimes, _parse_date
from ipython_genutils.py3compat import string_types
Expand Down Expand Up @@ -57,7 +58,8 @@ def check_ready(f, self, *args, **kwargs):
class AsyncResult(Future):
"""Class for representing results of non-blocking calls.

Provides the same interface as :py:class:`multiprocessing.pool.AsyncResult`.
Extends the interfaces of :py:class:`multiprocessing.pool.AsyncResult`
and :py:class:`concurrent.futures.Future`.
"""

msg_ids = None
Expand All @@ -73,6 +75,7 @@ def __init__(
fname='unknown',
targets=None,
owner=False,
progress_bar=tqdm.tqdm,
):
super(AsyncResult, self).__init__()
if not isinstance(children, list):
Expand All @@ -92,6 +95,7 @@ def __init__(
self._fname = fname
self._targets = targets
self.owner = owner
self.progress_bar = progress_bar

self._ready = False
self._ready_event = Event()
Expand Down Expand Up @@ -567,20 +571,21 @@ def wall_time(self):
return self.timedelta(self.submitted, self.received)

def wait_interactive(self, interval=1.0, timeout=-1):
"""interactive wait, printing progress at regular intervals"""
"""interactive wait, printing progress at regular intervals."""
if timeout is None:
timeout = -1
N = len(self)
tic = time.time()
while not self.ready() and (timeout < 0 or time.time() - tic <= timeout):
tic = time.perf_counter()
progress_bar = self.progress_bar(total=N, unit='tasks', desc=self._fname)
n_prev = 0
while not self.ready() and (
timeout < 0 or time.perf_counter() - tic <= timeout
):
self.wait(interval)
clear_output(wait=True)
print(
"%4i/%i tasks finished after %4i s" % (self.progress, N, self.elapsed),
end="",
)
sys.stdout.flush()
print("\ndone")
progress_bar.update(self.progress - n_prev)
n_prev = self.progress

progress_bar.close()

def _republish_displaypub(self, content, eid):
"""republish individual displaypub content dicts"""
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def run(self):
"ipykernel>=4.4",
"tornado>=5.1",
"python-dateutil>=2.1",
"tqdm",
],
python_requires=">=3.6",
extras_require={
Expand Down