Skip to content

Commit 3fbd934

Browse files
committed
use client.wait_for_engines in cluster context managers
1 parent 89f66ad commit 3fbd934

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

ipyparallel/cluster/cluster.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
starts/stops/polls controllers, engines, etc.
66
"""
77
import asyncio
8-
import atexit
98
import inspect
109
import logging
1110
import os
@@ -79,6 +78,15 @@ def _default_profile_dir(self):
7978
a shortcut for specifying profile_dir within $IPYTHONDIR.""",
8079
)
8180

81+
engine_timeout = Integer(
82+
60,
83+
help="""Timeout to use when waiting for engines to register
84+
85+
before giving up.
86+
""",
87+
config=True,
88+
)
89+
8290
controller_launcher_class = Launcher(
8391
default_value=launcher.LocalControllerLauncher,
8492
kind='Controller',
@@ -424,9 +432,11 @@ async def __aenter__(self):
424432
client = self._context_client = self.connect_client()
425433
if self.n:
426434
# wait for engine registration
427-
# TODO: timeout
428-
while len(client) < self.n:
429-
await asyncio.sleep(0.1)
435+
await asyncio.wrap_future(
436+
client.wait_for_engines(
437+
self.n, block=False, timeout=self.engine_timeout
438+
)
439+
)
430440
return client
431441

432442
async def __aexit__(self, *args):
@@ -442,8 +452,7 @@ def __enter__(self):
442452
client = self._context_client = self.connect_client()
443453
if self.n:
444454
# wait for engine registration
445-
while len(client) < self.n:
446-
time.sleep(0.1)
455+
client.wait_for_engines(self.n, block=True, timeout=self.engine_timeout)
447456
return client
448457

449458
def __exit__(self, *args):

0 commit comments

Comments
 (0)