Skip to content

Commit

Permalink
Another attempt to fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Blanca-Fuentes committed Dec 11, 2024
1 parent b7188ba commit a73343a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 45 deletions.
63 changes: 23 additions & 40 deletions reframe/core/schedulers/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
13 changes: 8 additions & 5 deletions reframe/utility/osext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit a73343a

Please sign in to comment.