Skip to content

Commit

Permalink
Merge pull request #5741 from clebergnu/proc_statemachine_fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Richter <[email protected]>
  • Loading branch information
richtja authored Aug 1, 2023
2 parents ef20b85 + e2f70c6 commit 7da1c75
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
21 changes: 16 additions & 5 deletions avocado/core/task/statemachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,24 @@ def __repr__(self):
)

async def _send_finished_tasks_message(self, terminate_tasks, reason):
"""Sends messages related to timeout to status repository.
When the task is terminated, it is necessary to send a finish message to status
repository to close logging. This method will send log message with timeout
information and finish message with right fail reason.
"""Sends messages related to tasks being terminated to status repository.
:param terminate_tasks: runtime_tasks which were terminated
On normal conditions, the "avocado-runner-*" will produce messages
finishing each task. But, under some conditions (such as timeouts,
interruptions requested by users, etc), it's necessary to do this on
the runner's behalf.
When a task is terminated, it is necessary to send a "finish" message
with the correct fail reason to the status repository, which will close
logging. This method will also send a "log" message with the reason
(timeout, user interruption, etc).
:param terminate_tasks: runtime_tasks which were terminated and need
to have messages sent on their behalf
:type terminate_tasks: list
:param reason: a description of what caused the task interruption (timeout, user
requested interruption, etc).
:type reason: str
"""
for terminated_task in terminate_tasks:
task_id = str(terminated_task.task.identifier)
Expand Down
6 changes: 3 additions & 3 deletions avocado/utils/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def safe_kill(pid, signal): # pylint: disable=W0621
:param signal: Signal number.
"""
if get_owner_id(int(pid)) == 0:
kill_cmd = f"kill -{int(int(signal))} {int(int(pid))}"
kill_cmd = f"kill -{int(signal)} {int(pid)}"
try:
run(kill_cmd, sudo=True)
return True
Expand Down Expand Up @@ -304,7 +304,7 @@ def process_in_ptree_is_defunct(ppid):
except CmdError: # Process doesn't exist
return True
for pid in pids:
cmd = f"ps --no-headers -o cmd {int(int(pid))}"
cmd = f"ps --no-headers -o cmd {int(pid)}"
proc_name = system_output(cmd, ignore_status=True, verbose=False)
if "<defunct>" in proc_name:
defunct = True
Expand Down Expand Up @@ -795,7 +795,7 @@ def send_signal(self, sig):
pids = get_children_pids(self.get_pid())
pids.append(self.get_pid())
for pid in pids:
kill_cmd = f"kill -{int(int(sig))} {int(pid)}"
kill_cmd = f"kill -{int(sig)} {int(pid)}"
with contextlib.suppress(Exception):
run(kill_cmd, sudo=True)
else:
Expand Down

0 comments on commit 7da1c75

Please sign in to comment.