From a73343ace374ccbfd02ad7e8742dc53475f10a32 Mon Sep 17 00:00:00 2001 From: Blanca Fuentes Date: Wed, 11 Dec 2024 09:24:41 +0100 Subject: [PATCH] Another attempt to fix tests --- reframe/core/schedulers/local.py | 63 ++++++++++++-------------------- reframe/utility/osext.py | 13 ++++--- 2 files changed, 31 insertions(+), 45 deletions(-) diff --git a/reframe/core/schedulers/local.py b/reframe/core/schedulers/local.py index 69c128620..c76546058 100644 --- a/reframe/core/schedulers/local.py +++ b/reframe/core/schedulers/local.py @@ -109,62 +109,45 @@ def _kill_all(self, job): children = [] try: - # Try to kill the main process - os.kill(job.jobid, signal.SIGKILL) + for child in children: + if child.is_running(): + child.send_signal(signal.SIGKILL) + job._signal = signal.SIGKILL + else: + self.log(f'child pid {child.pid} already dead') + job.proc.send_signal(signal.SIGKILL) job._signal = signal.SIGKILL except (ProcessLookupError, PermissionError): # The process group may already be dead or assigned to a different # group, so ignore this error self.log(f'pid {job.jobid} already dead') - if job.proc.returncode: - if job.proc.returncode >= 0: - job._signal = signal.SIGKILL finally: # Close file handles job.f_stdout.close() job.f_stderr.close() job._state = 'FAILURE' - # for child in children: - # # try to kill the children - # try: - # child.kill() - # except (ProcessLookupError, PermissionError, - # psutil.NoSuchProcess): - # # The process group may already be dead or assigned - # # to a different group, so ignore this error - # self.log(f'child pid {child.pid} already dead') - # else: - # # If the main process was terminated but the children - # # ignored the term signal, then the child are killed - # if job.proc.returncode: - # if job.proc.returncode == -15: - # job._signal = signal.SIGKILL - def _term_all(self, job): '''Send SIGTERM to all the processes of the spawned job.''' - try: - p = psutil.Process(job.jobid) - job.children = p.children(recursive=True) - children = job.children - except psutil.NoSuchProcess: - try: - children = job.children - except AttributeError: - children = [] + + p = psutil.Process(job.jobid) + # Get the chilldren of the process + job.children = p.children(recursive=True) try: - # for child in children: - # try: - # child.terminate() - # child.signal = signal.SIGTERM - # except (ProcessLookupError, PermissionError, - # psutil.NoSuchProcess): - # # The process group may already be dead or assigned - # # to a different group, so ignore this error - # self.log(f'child pid {child.pid} already dead') - os.kill(job.jobid, signal.SIGTERM) + job.proc.send_signal(signal.SIGTERM) job._signal = signal.SIGTERM + # Here, we don't know if it was ignored or not + for child in job.children: + # try to kill the children + try: + child.send_signal(signal.SIGTERM) + except (ProcessLookupError, PermissionError, + psutil.NoSuchProcess): + # The process group may already be dead or assigned + # to a different group, so ignore this error + self.log(f'child pid {child.pid} already dead') + except (ProcessLookupError, PermissionError): # Job has finished already, close file handles self.log(f'pid {job.jobid} already dead') diff --git a/reframe/utility/osext.py b/reframe/utility/osext.py index 5d6550cd5..76dd2cee9 100644 --- a/reframe/utility/osext.py +++ b/reframe/utility/osext.py @@ -360,16 +360,17 @@ async def run_command_asyncio_alone(cmd, # Call create_subprocess_shell return await asyncio.create_subprocess_shell( cmd, stdout=stdout, - stderr=stderr + stderr=stderr, + **kwargs ) else: # Call create_subprocess_exec return await asyncio.create_subprocess_exec( cmd, stdout=stdout, - stderr=stderr + stderr=stderr, + **kwargs ) - async def run_command_asyncio(cmd, check=False, timeout=None, @@ -390,13 +391,15 @@ async def run_command_asyncio(cmd, # Call create_subprocess_shell proc = await asyncio.create_subprocess_shell( cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE + stderr=subprocess.PIPE, + **kwargs ) else: # Call create_subprocess_exec proc = await asyncio.create_subprocess_exec( cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE + stderr=subprocess.PIPE, + **kwargs ) proc_stdout, proc_stderr = await asyncio.wait_for( proc.communicate(), timeout=timeout