Skip to content

Commit 44c32f3

Browse files
committed
handle short-circuit in wait_for_engines(block=False)
1 parent 66b18dd commit 44c32f3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

ipyparallel/client/client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,12 @@ def wait_for_engines(self, n, *, timeout=-1, block=True):
13341334
TimeoutError : if timeout is reached.
13351335
"""
13361336
if len(self.ids) >= n:
1337-
return
1337+
if block:
1338+
return
1339+
else:
1340+
f = Future()
1341+
f.set_result(None)
1342+
return f
13381343
tic = now = time.perf_counter()
13391344
if timeout >= 0:
13401345
deadline = tic + timeout
@@ -1363,7 +1368,7 @@ def on_timeout():
13631368
else:
13641369
future.set_exception(
13651370
TimeoutError(
1366-
"{n} engines not ready in {timeout} seconds. Currently ready: {len(self.ids)}"
1371+
f"{n} engines not ready in {timeout} seconds. Currently ready: {len(self.ids)}"
13671372
)
13681373
)
13691374

ipyparallel/tests/test_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,11 @@ def test_local_ip_true_doesnt_trigger_warning(self):
646646
def test_wait_for_engines(self):
647647
n = len(self.client)
648648
assert self.client.wait_for_engines(n) is None
649+
650+
f = self.client.wait_for_engines(n, block=False)
651+
assert isinstance(f, Future)
652+
assert f.done()
653+
649654
with pytest.raises(TimeoutError):
650655
self.client.wait_for_engines(n + 1, timeout=0.1)
651656

0 commit comments

Comments
 (0)