mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Don't run the same signal handler twice. Catch os.kill errors.
Else a Process Not Found error stops the killing loop and there are still alive master subprocesses.
This commit is contained in:
parent
1d5f97d36b
commit
ca8eb7e076
1 changed files with 11 additions and 2 deletions
|
@ -409,6 +409,10 @@ class ProcessManager(object):
|
|||
'''
|
||||
Kill all of the children
|
||||
'''
|
||||
# first lets reset signal handlers to default one to prevent running this twice
|
||||
signal.signal(signal.SIGTERM, signal.SIG_IGN)
|
||||
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
||||
|
||||
# check that this is the correct process, children inherit this
|
||||
# handler, if we are in a child lets just run the original handler
|
||||
if os.getpid() != self._pid:
|
||||
|
@ -433,7 +437,10 @@ class ProcessManager(object):
|
|||
log.trace('Terminating pid {0}: {1}'.format(pid, p_map['Process']))
|
||||
if args:
|
||||
# escalate the signal to the process
|
||||
os.kill(pid, args[0])
|
||||
try:
|
||||
os.kill(pid, args[0])
|
||||
except OSError:
|
||||
pass
|
||||
try:
|
||||
p_map['Process'].terminate()
|
||||
except OSError as exc:
|
||||
|
@ -477,7 +484,7 @@ class ProcessManager(object):
|
|||
continue
|
||||
log.trace('Killing pid {0}: {1}'.format(pid, p_map['Process']))
|
||||
try:
|
||||
os.kill(signal.SIGKILL, pid)
|
||||
os.kill(pid, signal.SIGKILL)
|
||||
except OSError:
|
||||
# in case the process has since decided to die, os.kill returns OSError
|
||||
if not p_map['Process'].is_alive():
|
||||
|
@ -648,6 +655,8 @@ class SignalHandlingMultiprocessingProcess(MultiprocessingProcess):
|
|||
signal.signal(signal.SIGTERM, self._handle_signals)
|
||||
|
||||
def _handle_signals(self, signum, sigframe):
|
||||
signal.signal(signal.SIGTERM, signal.SIG_IGN)
|
||||
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
||||
msg = '{0} received a '.format(self.__class__.__name__)
|
||||
if signum == signal.SIGINT:
|
||||
msg += 'SIGINT'
|
||||
|
|
Loading…
Add table
Reference in a new issue