From 68c29af9ed7537cf11edb8ef36d2e40fa950569f Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Thu, 25 Jul 2019 15:32:33 -0600 Subject: [PATCH] Allow for main thread having terminated pid, before ThreadPoolExecutor threads --- salt/utils/process.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/salt/utils/process.py b/salt/utils/process.py index a0c31fb1d9..300747384f 100644 --- a/salt/utils/process.py +++ b/salt/utils/process.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# ndle-*- coding: utf-8 -*- ''' Functions for daemonizing and otherwise modifying running processes ''' @@ -807,11 +807,15 @@ class SignalHandlingMultiprocessingProcess(MultiprocessingProcess): msg += '. Exiting' log.debug(msg) if HAS_PSUTIL: - process = psutil.Process(self.pid) - if hasattr(process, 'children'): - for child in process.children(recursive=True): - if child.is_running(): - child.terminate() + for process in psutil.process_iter(): + if process == self.pid and hasattr(process, 'children'): + try: + for child in process.children(recursive=True): + if child.is_running(): + child.terminate() + except psutil.NoSuchProcess: + pass + break sys.exit(salt.defaults.exitcodes.EX_OK) def start(self):