Skip to content
Open
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
14 changes: 10 additions & 4 deletions lab/calls/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,19 @@ def _update_cpu_time(self):

def _terminate_process_group(self):
"""Terminate the entire process group (parent and all children)."""
try:
pgid = os.getpgid(self.process.pid)
except (OSError, ProcessLookupError):
return

with contextlib.suppress(OSError, ProcessLookupError):
os.killpg(os.getpgid(self.process.pid), signal.SIGTERM)
os.killpg(pgid, signal.SIGTERM)

# Give it a moment to terminate gracefully.
time.sleep(1)
if self.process.poll() is None:
with contextlib.suppress(OSError, ProcessLookupError):
os.killpg(os.getpgid(self.process.pid), signal.SIGKILL)

with contextlib.suppress(OSError, ProcessLookupError):
os.killpg(pgid, signal.SIGKILL)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the rationale for this change? I don't think it's good style to kill a process that we know has terminated. Is poll not reliable? If the process has terminated, it will be in zombie state here. Better to have it finish normally than kill it, I would say, if it has terminated in the one-second grace period.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that we are currently using poll() on the leader process as a proxy for whether the whole process group has terminated.

Before, if the leader spawned child processes, it could happen that the leader exited after SIGTERM while some children were still running. In that case, poll() would return the leader’s exit code rather than None.


def _monitor_time_limits(self):
"""
Expand Down
Loading