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`.
This commit is contained in:
Martine S. Lenders
2020-04-28 19:42:07 +02:00
parent 40c3de4b0f
commit aee9f09386
+10 -2
View File
@@ -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()