Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/google/adk/code_executors/unsafe_local_code_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ def _kill_execution(process: subprocess.Popen[str]) -> tuple[str, str]:

# Escalate unconditionally: the execution process exiting says nothing about
# a child of it that is ignoring SIGTERM, and such a child holds the output
# pipes open besides.
_signal_group(group, signal.SIGKILL)
# pipes open besides. `_signal_group` no-ops on the platforms that have no
# process groups, so the fallback signal is never sent by it.
_signal_group(group, getattr(signal, 'SIGKILL', signal.SIGTERM))
process.kill()
try:
return process.communicate(timeout=_TERMINATE_GRACE_SECONDS)
Expand Down
6 changes: 4 additions & 2 deletions src/google/adk/environment/_local_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,10 @@ async def _kill_command(
if not done:
# Escalate unconditionally: the command exiting says nothing about a
# child of it that is ignoring SIGTERM, and such a child holds the
# output pipes open besides.
_signal_group(group, signal.SIGKILL)
# output pipes open besides. `_signal_group` no-ops on the platforms
# that have no process groups, so the fallback signal is never sent by
# it.
_signal_group(group, getattr(signal, 'SIGKILL', signal.SIGTERM))
_kill(proc)
done, _ = await asyncio.wait([drain], timeout=_TERMINATE_GRACE_SECONDS)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ def test_execute_code_imports_resolve_from_the_agent_path(
assert result.stdout == "imported\n"
assert result.stderr == ""

@pytest.mark.skipif(
not hasattr(os, "killpg"), reason="needs POSIX process groups"
)
def test_kill_execution_signals_group_before_killing_it(self, monkeypatch):
"""The group gets SIGTERM and its grace period before SIGKILL."""
signalled = []
Expand Down
Loading