30
30
from .futures import MessageFuture , multi_future
31
31
32
32
33
- try :
34
- from tqdm import tqdm
35
- use_progressbar = True
36
- except ImportError :
37
- use_progressbar = False
38
-
39
-
40
33
def _raw_text (s ):
41
34
display_pretty (s , raw = True )
42
35
@@ -573,14 +566,18 @@ def wall_time(self):
573
566
"""
574
567
return self .timedelta (self .submitted , self .received )
575
568
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
578
575
if timeout is None :
579
576
timeout = - 1
580
577
N = len (self )
581
578
tic = time .time ()
582
579
if use_progressbar :
583
- progress_bar = tqdm (total = N )
580
+ progress_bar = progress (total = N )
584
581
n_prev = 0
585
582
while not self .ready () and (timeout < 0 or time .time () - tic <= timeout ):
586
583
self .wait (interval )
@@ -589,8 +586,11 @@ def wait_interactive(self, interval=1.0, timeout=-1):
589
586
n_prev = self .progress
590
587
else :
591
588
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
+ )
594
594
sys .stdout .flush ()
595
595
596
596
if use_progressbar :
0 commit comments