Skip to content

Commit

Permalink
Don't restart process if we're already terminating
Browse files Browse the repository at this point in the history
  • Loading branch information
yuvipanda committed Dec 24, 2018
1 parent 5b2e558 commit 693ef93
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion simpervisor/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def __init__(self, name, *args, always_restart=False, **kwargs):
# Don't restart process if we explicitly kill it
self._killed = False

# Don't restart process if we are terminating after SIGTERM / SIGINT
self._terminating = False

# Only one coroutine should be starting or killing a process at a time
self._start_stop_lock = asyncio.Lock()

Expand All @@ -38,9 +41,17 @@ def _debug_log(self, action, message, extras=None):
self.log.debug(message, extra=base_extras)

def _handle_signal(self, signal):
# Child processes should handle SIGTERM / SIGINT & close,
# which should trigger self._restart_process_if_needed
# We don't explicitly reap child processe
self.proc.send_signal(signal)
# Don't restart process after it is reaped
self._terminating = True
self._debug_log('signal', f'Propagated signal {signal} to {self.name}')

def wait(self):
return self.proc.wait()

async def start(self):
"""
Start the process
Expand Down Expand Up @@ -70,7 +81,7 @@ async def _restart_process_if_needed(self):
{'code': retcode}
)
self.running = False
if (not self._killed) and (self.always_restart or retcode != 0):
if (not self._terminating) and (not self._killed) and (self.always_restart or retcode != 0):
await self.start()

async def kill(self):
Expand Down

0 comments on commit 693ef93

Please sign in to comment.