Skip to content

Commit 2f52cfc

Browse files
cphycminrk
authored andcommitted
the progressbar is now passed as an extra argument to wait_interactive
1 parent ecf54e4 commit 2f52cfc

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

ipyparallel/client/asyncresult.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@
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-
4033
def _raw_text(s):
4134
display_pretty(s, raw=True)
4235

@@ -573,14 +566,18 @@ def wall_time(self):
573566
"""
574567
return self.timedelta(self.submitted, self.received)
575568

576-
def wait_interactive(self, interval=1.0, timeout=-1):
577-
"""interactive wait, printing progress at regular intervals"""
569+
def wait_interactive(self, interval=1.0, timeout=-1, progress=None):
570+
"""interactive wait, printing progress at regular intervals.
571+
572+
progress can be a tqdm-like progress bar."""
573+
574+
use_progressbar = progress is not None
578575
if timeout is None:
579576
timeout = -1
580577
N = len(self)
581578
tic = time.time()
582579
if use_progressbar:
583-
progress_bar = tqdm(total=N)
580+
progress_bar = progress(total=N)
584581
n_prev = 0
585582
while not self.ready() and (timeout < 0 or time.time() - tic <= timeout):
586583
self.wait(interval)
@@ -589,8 +586,11 @@ def wait_interactive(self, interval=1.0, timeout=-1):
589586
n_prev = self.progress
590587
else:
591588
clear_output(wait=True)
592-
print("%4i/%i tasks finished after %4i s" %
593-
(self.progress, N, self.elapsed), end="")
589+
print(
590+
"%4i/%i tasks finished after %4i s"
591+
% (self.progress, N, self.elapsed),
592+
end="",
593+
)
594594
sys.stdout.flush()
595595

596596
if use_progressbar:

0 commit comments

Comments
 (0)