aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mtest.py
diff options
context:
space:
mode:
authorCamilo Celis Guzman <camilo@pexip.com>2020-01-25 23:14:07 +0100
committerJussi Pakkanen <jpakkane@gmail.com>2020-03-19 23:04:36 +0200
commit18373cba743e16e502e18d795af360600f9fd44d (patch)
treed17d106c373f86ea6a3d32b8fefbf1d784985a40 /mesonbuild/mtest.py
parent4d6faf6a136018405e4de17e2173df76d37b48dd (diff)
downloadmeson-18373cba743e16e502e18d795af360600f9fd44d.zip
meson-18373cba743e16e502e18d795af360600f9fd44d.tar.gz
meson-18373cba743e16e502e18d795af360600f9fd44d.tar.bz2
mtest: terminate a test via SIGTERM first then (if needed) via SIGKILL
Diffstat (limited to 'mesonbuild/mtest.py')
-rw-r--r--mesonbuild/mtest.py27
1 files changed, 20 insertions, 7 deletions
diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py
index 32b87c6..c35ab5a 100644
--- a/mesonbuild/mtest.py
+++ b/mesonbuild/mtest.py
@@ -578,14 +578,27 @@ class SingleTestRunner:
if is_windows():
subprocess.run(['taskkill', '/F', '/T', '/PID', str(p.pid)])
else:
+
+ def _send_signal_to_process_group(pgid : int, signum : int):
+ """ sends a signal to a process group """
+ try:
+ os.killpg(pgid, signum) # type: ignore
+ except ProcessLookupError:
+ # Sometimes (e.g. with Wine) this happens.
+ # There's nothing we can do (maybe the process
+ # already died) so carry on.
+ pass
+
+ # Send a termination signal to the process group that setsid()
+ # created - giving it a chance to perform any cleanup.
+ _send_signal_to_process_group(p.pid, signal.SIGTERM)
+
+ # Make sure the termination signal actually kills the process
+ # group, otherwise retry with a SIGKILL.
try:
- # Kill the process group that setsid() created.
- os.killpg(p.pid, signal.SIGKILL) # type: ignore
- except ProcessLookupError:
- # Sometimes (e.g. with Wine) this happens.
- # There's nothing we can do (maybe the process
- # already died) so carry on.
- pass
+ p.communicate(timeout=0.5)
+ except subprocess.TimeoutExpired:
+ _send_signal_to_process_group(p.pid, signal.SIGKILL)
try:
p.communicate(timeout=1)
except subprocess.TimeoutExpired: