Skip to content

Commit ecf54e4

Browse files
cphycminrk
authored andcommitted
use progressbar when available
1 parent cc3a528 commit ecf54e4

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

ipyparallel/client/asyncresult.py

+23-7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
from .futures import MessageFuture, multi_future
3131

3232

33+
try:
34+
from tqdm import tqdm
35+
use_progressbar = True
36+
except ImportError:
37+
use_progressbar = False
38+
39+
3340
def _raw_text(s):
3441
display_pretty(s, raw=True)
3542

@@ -572,15 +579,24 @@ def wait_interactive(self, interval=1.0, timeout=-1):
572579
timeout = -1
573580
N = len(self)
574581
tic = time.time()
582+
if use_progressbar:
583+
progress_bar = tqdm(total=N)
584+
n_prev = 0
575585
while not self.ready() and (timeout < 0 or time.time() - tic <= timeout):
576586
self.wait(interval)
577-
clear_output(wait=True)
578-
print(
579-
"%4i/%i tasks finished after %4i s" % (self.progress, N, self.elapsed),
580-
end="",
581-
)
582-
sys.stdout.flush()
583-
print("\ndone")
587+
if use_progressbar:
588+
progress_bar.update(self.progress - n_prev)
589+
n_prev = self.progress
590+
else:
591+
clear_output(wait=True)
592+
print("%4i/%i tasks finished after %4i s" %
593+
(self.progress, N, self.elapsed), end="")
594+
sys.stdout.flush()
595+
596+
if use_progressbar:
597+
progress_bar.close()
598+
else:
599+
print("\ndone")
584600

585601
def _republish_displaypub(self, content, eid):
586602
"""republish individual displaypub content dicts"""

0 commit comments

Comments
 (0)