@@ -327,7 +327,25 @@ async def _replace(self, slot: _Slot) -> None:
327327
328328 async def _start (self , slot : _Slot ) -> None :
329329 '''Start ``slot``'s process and wait until it is ready; raise
330- ``PoolError`` (and delay the next try) if it isn't.
330+ ``PoolError`` (and delay the next try) if it isn't, whatever the
331+ reason (e.g. no process could be started at all).
332+ '''
333+ try :
334+ await self ._launch (slot )
335+ except Exception as ex :
336+ returncode = await self ._stop (slot )
337+ slot .process = None
338+ slot .failed_starts += 1
339+ delay = min (2.0 ** (slot .failed_starts - 1 ), _MAX_RESTART_DELAY_S )
340+ slot .not_before = time .monotonic () + delay
341+ _log .error ('pool process %d failed to start (%s; exit status %s); '
342+ 'trying again in %g s' , slot .index , ex , returncode , delay )
343+ raise PoolError (f"pool process { slot .index } failed to start" ) from ex
344+ slot .failed_starts = 0
345+
346+ async def _launch (self , slot : _Slot ) -> None :
347+ '''Start ``slot``'s process and wait until it is ready; raise if it
348+ isn't.
331349 '''
332350 parent_end , process_end = socket .socketpair ()
333351 try :
@@ -360,15 +378,7 @@ async def _start(self, slot: _Slot) -> None:
360378 self ._kill (slot )
361379 raise
362380 if ready .strip () != b'{"ready": true}' :
363- returncode = await self ._stop (slot )
364- slot .process = None
365- slot .failed_starts += 1
366- delay = min (2.0 ** (slot .failed_starts - 1 ), _MAX_RESTART_DELAY_S )
367- slot .not_before = time .monotonic () + delay
368- _log .error ('pool process %d failed to start (%s); trying again in '
369- '%g s' , slot .index , returncode , delay )
370- raise PoolError (f"pool process { slot .index } failed to start" )
371- slot .failed_starts = 0
381+ raise PoolError ('it never said it was ready' )
372382 _log .info ('started pool process %d (pid %d)' , slot .index , process .pid )
373383
374384 def _kill (self , slot : _Slot ) -> None :
0 commit comments