From 36c5698833b1abda516d7630b7b9ad483f2f2f07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Bl=C3=BChdorn?= Date: Wed, 28 Sep 2022 11:58:06 +0200 Subject: [PATCH] Ensure that the test script does not kill itself. --- TestCases/TestCase.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/TestCases/TestCase.py b/TestCases/TestCase.py index 5761a2b9155..53a9355db7a 100644 --- a/TestCases/TestCase.py +++ b/TestCases/TestCase.py @@ -45,7 +45,7 @@ class Command: launch : str e.g. "mpirun -n 2", possibly empty exec : str - e.g. "SU2_CFD", must be a suitable argument to killall to clean up what the command started + e.g. "SU2_CFD", must be suitable to identify the processes started by the command param : str e.g. "-t 2", possibly empty """ @@ -62,6 +62,10 @@ def assemble(self): assert self.exec != "" return " ".join([part for part in [self.launch, self.exec, self.param] if part != ""]) + def killall(self): + """ Issues a shell command that kills all processes matching self.exec, except this process. """ + os.system('pgrep %s | grep -vx %d | xargs kill -9' % (self.exec, os.getpid())) + def __init__(self,tag_in): @@ -158,7 +162,7 @@ def run_test(self): if running_time > self.timeout: try: process.kill() - os.system('killall %s' % self.command.exec) # In case of parallel execution + self.command.killall() # In case of parallel execution except AttributeError: # popen.kill apparently fails on some versions of subprocess... the killall command should take care of things! pass timed_out = True @@ -298,7 +302,7 @@ def run_filediff(self): if running_time > self.timeout: try: process.kill() - os.system('killall %s' % self.command.exec) # In case of parallel execution + self.command.killall() # In case of parallel execution except AttributeError: # popen.kill apparently fails on some versions of subprocess... the killall command should take care of things! pass timed_out = True @@ -391,7 +395,7 @@ def run_opt(self): if running_time > self.timeout: try: process.kill() - os.system('killall %s' % self.command.exec) # In case of parallel execution + self.command.killall() # In case of parallel execution except AttributeError: # popen.kill apparently fails on some versions of subprocess... the killall command should take care of things! pass timed_out = True @@ -523,7 +527,7 @@ def run_geo(self): if running_time > self.timeout: try: process.kill() - os.system('killall %s' % self.command.exec) # In case of parallel execution + self.command.killall() # In case of parallel execution except AttributeError: # popen.kill apparently fails on some versions of subprocess... the killall command should take care of things! pass timed_out = True @@ -652,7 +656,7 @@ def run_def(self): if running_time > self.timeout: try: process.kill() - os.system('killall %s' % self.command.exec) # In case of parallel execution + self.command.killall() # In case of parallel execution except AttributeError: # popen.kill apparently fails on some versions of subprocess... the killall command should take care of things! pass timed_out = True