diff --git a/tools/testrunner/local/command.py b/tools/testrunner/local/command.py index 053ef30710..7792c56d94 100644 --- a/tools/testrunner/local/command.py +++ b/tools/testrunner/local/command.py @@ -184,6 +184,22 @@ class PosixCommand(BaseCommand): process.kill() +def taskkill_windows(process, verbose=False, force=True): + force_flag = ' /F' if force else '' + tk = subprocess.Popen( + 'taskkill /T%s /PID %d' % (force_flag, process.pid), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + stdout, stderr = tk.communicate() + if verbose: + print('Taskkill results for %d' % process.pid) + print(stdout) + print(stderr) + print('Return code: %d' % tk.returncode) + sys.stdout.flush() + + class WindowsCommand(BaseCommand): def _start_process(self, **kwargs): # Try to change the error mode to avoid dialogs on fatal errors. Don't @@ -213,18 +229,7 @@ class WindowsCommand(BaseCommand): return subprocess.list2cmdline(self._to_args_list()) def _kill_process(self, process): - tk = subprocess.Popen( - 'taskkill /T /F /PID %d' % process.pid, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - ) - stdout, stderr = tk.communicate() - if self.verbose: - print('Taskkill results for %d' % process.pid) - print(stdout) - print(stderr) - print('Return code: %d' % tk.returncode) - sys.stdout.flush() + taskkill_windows(process, self.verbose) class AndroidCommand(BaseCommand): diff --git a/tools/testrunner/local/pool.py b/tools/testrunner/local/pool.py index 9defdd30ee..a6fb91f912 100644 --- a/tools/testrunner/local/pool.py +++ b/tools/testrunner/local/pool.py @@ -19,6 +19,7 @@ except ImportError: from Queue import Empty # Python 2 from . import command +from . import utils def setup_testing(): @@ -243,6 +244,13 @@ class Pool(): """ self.abort_now = True + def _terminate_processes(self): + for p in self.processes: + if utils.IsWindows(): + command.taskkill_windows(p, verbose=True, force=False) + else: + os.kill(p.pid, signal.SIGTERM) + def _terminate(self): """Terminates execution and cleans up the queues. @@ -267,8 +275,7 @@ class Pool(): self.work_queue.put("STOP") if self.abort_now: - for p in self.processes: - os.kill(p.pid, signal.SIGTERM) + self._terminate_processes() self.notify("Joining workers") for p in self.processes: