@@ -310,30 +310,34 @@ async def start_unsafe(self):
310
310
return self
311
311
312
312
async def start (self ):
313
- async with self ._startup_lock :
314
- if self .status == Status .failed :
315
- assert self .__startup_exc is not None
316
- raise self .__startup_exc
317
- elif self .status != Status .init :
318
- return self
319
- timeout = getattr (self , "death_timeout" , None )
320
-
321
- async def _close_on_failure (exc : Exception ) -> None :
322
- await self .close ()
323
- self .status = Status .failed
324
- self .__startup_exc = exc
313
+ try :
314
+ async with self ._startup_lock :
315
+ if self .status == Status .failed :
316
+ assert self .__startup_exc is not None
317
+ raise self .__startup_exc
318
+ elif self .status != Status .init :
319
+ return self
320
+ timeout = getattr (self , "death_timeout" , None )
321
+
322
+ async def _close_on_failure (exc : Exception ) -> None :
323
+ await self .close ()
324
+ self .status = Status .failed
325
+ self .__startup_exc = exc
325
326
326
- try :
327
- await asyncio .wait_for (self .start_unsafe (), timeout = timeout )
328
- except asyncio .TimeoutError as exc :
329
- await _close_on_failure (exc )
330
- raise asyncio .TimeoutError (
331
- f"{ type (self ).__name__ } start timed out after { timeout } s."
332
- ) from exc
333
- except Exception as exc :
334
- await _close_on_failure (exc )
335
- raise RuntimeError (f"{ type (self ).__name__ } failed to start." ) from exc
336
- self .status = Status .running
327
+ try :
328
+ await asyncio .wait_for (self .start_unsafe (), timeout = timeout )
329
+ except asyncio .TimeoutError as exc :
330
+ await _close_on_failure (exc )
331
+ raise asyncio .TimeoutError (
332
+ f"{ type (self ).__name__ } start timed out after { timeout } s."
333
+ ) from exc
334
+ except Exception as exc :
335
+ await _close_on_failure (exc )
336
+ raise RuntimeError (
337
+ f"{ type (self ).__name__ } failed to start."
338
+ ) from exc
339
+ self .status = Status .running
340
+ finally :
337
341
self .__started .set ()
338
342
return self
339
343
@@ -515,7 +519,7 @@ async def handle_comm(self, comm):
515
519
logger .debug ("Connection from %r to %s" , address , type (self ).__name__ )
516
520
self ._comms [comm ] = op
517
521
518
- await self
522
+ await self . __started . wait ()
519
523
try :
520
524
while not self .__stopped :
521
525
try :
0 commit comments