10
10
from contextlib import contextmanager
11
11
from datetime import datetime
12
12
from functools import partial
13
+ from queue import Queue
13
14
from threading import Event
14
15
15
- try :
16
- from queue import Queue
17
- except ImportError : # py2
18
- from Queue import Queue
19
-
20
- from decorator import decorator
21
- import tqdm
22
16
import zmq
23
- from zmq import MessageTracker
24
-
17
+ from decorator import decorator
25
18
from IPython import get_ipython
26
- from IPython .core .display import display , display_pretty
27
- from ipyparallel import error
28
- from ipyparallel .util import utcnow , compare_datetimes , _parse_date
19
+ from IPython .core .display import display
20
+ from IPython .core .display import display_pretty
29
21
from ipython_genutils .py3compat import string_types
30
22
31
- from .futures import MessageFuture , multi_future
23
+ from .futures import MessageFuture
24
+ from .futures import multi_future
25
+ from ipyparallel import error
26
+ from ipyparallel .util import _parse_date
27
+ from ipyparallel .util import compare_datetimes
28
+ from ipyparallel .util import progress
29
+ from ipyparallel .util import utcnow
32
30
33
31
34
32
def _raw_text (s ):
@@ -38,7 +36,7 @@ def _raw_text(s):
38
36
_default = object ()
39
37
40
38
# global empty tracker that's always done:
41
- finished_tracker = MessageTracker ()
39
+ finished_tracker = zmq . MessageTracker ()
42
40
43
41
44
42
@decorator
@@ -75,7 +73,6 @@ def __init__(
75
73
fname = 'unknown' ,
76
74
targets = None ,
77
75
owner = False ,
78
- progress_bar = tqdm .tqdm ,
79
76
):
80
77
super (AsyncResult , self ).__init__ ()
81
78
if not isinstance (children , list ):
@@ -95,7 +92,6 @@ def __init__(
95
92
self ._fname = fname
96
93
self ._targets = targets
97
94
self .owner = owner
98
- self .progress_bar = progress_bar
99
95
100
96
self ._ready = False
101
97
self ._ready_event = Event ()
@@ -381,7 +377,7 @@ def _handle_sent(self, f):
381
377
"""Resolve sent Future, build MessageTracker"""
382
378
trackers = f .result ()
383
379
trackers = [t for t in trackers if t is not None ]
384
- self ._tracker = MessageTracker (* trackers )
380
+ self ._tracker = zmq . MessageTracker (* trackers )
385
381
self ._sent_event .set ()
386
382
387
383
@property
@@ -569,13 +565,27 @@ def wall_time(self):
569
565
"""
570
566
return self .timedelta (self .submitted , self .received )
571
567
572
- def wait_interactive (self , interval = 1.0 , timeout = - 1 ):
573
- """interactive wait, printing progress at regular intervals."""
568
+ def wait_interactive (self , interval = 0.1 , timeout = - 1 , widget = None ):
569
+ """interactive wait, printing progress at regular intervals.
570
+
571
+ Parameters
572
+ ----------
573
+ interval : float
574
+ Interval on which to update progress display.
575
+ timeout : float
576
+ Time (in seconds) to wait before raising a TimeoutError.
577
+ -1 (default) means no timeout.
578
+ widget : bool
579
+ default: True if in an IPython kernel (notebook), False otherwise.
580
+ Override default context-detection behavior for whether a widget-based progress bar
581
+ should be used.
582
+ """
574
583
if timeout is None :
575
584
timeout = - 1
576
585
N = len (self )
577
586
tic = time .perf_counter ()
578
- progress_bar = self .progress_bar (total = N , unit = 'tasks' , desc = self ._fname )
587
+ progress_bar = progress (widget = widget , total = N , unit = 'tasks' , desc = self ._fname )
588
+
579
589
n_prev = 0
580
590
while not self .ready () and (
581
591
timeout < 0 or time .perf_counter () - tic <= timeout
0 commit comments