5
5
starts/stops/polls controllers, engines, etc.
6
6
"""
7
7
import asyncio
8
- import atexit
9
8
import inspect
10
9
import logging
11
10
import os
@@ -79,6 +78,15 @@ def _default_profile_dir(self):
79
78
a shortcut for specifying profile_dir within $IPYTHONDIR.""" ,
80
79
)
81
80
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
+
82
90
controller_launcher_class = Launcher (
83
91
default_value = launcher .LocalControllerLauncher ,
84
92
kind = 'Controller' ,
@@ -424,9 +432,11 @@ async def __aenter__(self):
424
432
client = self ._context_client = self .connect_client ()
425
433
if self .n :
426
434
# 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
+ )
430
440
return client
431
441
432
442
async def __aexit__ (self , * args ):
@@ -442,8 +452,7 @@ def __enter__(self):
442
452
client = self ._context_client = self .connect_client ()
443
453
if self .n :
444
454
# 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 )
447
456
return client
448
457
449
458
def __exit__ (self , * args ):
0 commit comments