[testrunner] Properly terminate worker processes on Windows

Bug: v8:8170
Change-Id: I4b4a2919f6cf613779eeabc6c2cec1b08fa4d80f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1981152
Reviewed-by: Tamer Tas <tmrts@chromium.org>
Commit-Queue: Michael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65626}
This commit is contained in:
Michael Achenbach 2020-01-08 11:03:44 +01:00 committed by Commit Bot
parent 31668eb256
commit 92b3a4779f
2 changed files with 26 additions and 14 deletions

View File

@ -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):

View File

@ -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: