From aee9f09386a1a7dc9fb73dd622831bba729ea38d Mon Sep 17 00:00:00 2001 From: "Martine S. Lenders" Date: Fri, 17 Apr 2020 16:22:59 +0200 Subject: [PATCH] testrunner: use SIGKILL only as last resort When the child has a clean-up step (closing files, killing sub-processes, deleting operational files, etc.), this currently is not executed by the test, as the `testrunner` just does a hard `SIGKILL` for the child's PPID. This change makes this a `SIGTERM` and only uses `SIGKILL` if there are still processes lingering a second after the `SIGTERM`. --- dist/pythonlibs/testrunner/spawn.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/dist/pythonlibs/testrunner/spawn.py b/dist/pythonlibs/testrunner/spawn.py index 032618a244..c7daa61558 100644 --- a/dist/pythonlibs/testrunner/spawn.py +++ b/dist/pythonlibs/testrunner/spawn.py @@ -89,11 +89,19 @@ def setup_child(timeout=10, spawnclass=pexpect.spawnu, env=None, logfile=None): def teardown_child(child): + pid = child.pid try: - os.killpg(os.getpgid(child.pid), signal.SIGKILL) + os.killpg(os.getpgid(pid), signal.SIGTERM) except ProcessLookupError: print("Process already stopped") - + else: + time.sleep(1) + # kill still lingering processes + try: + os.killpg(os.getpgid(pid), signal.SIGKILL) + except ProcessLookupError: + # This is what we actually wanted + pass child.close()