bneradt commented on code in PR #13964:
URL: https://github.com/apache/trafficserver/pull/13964#discussion_r4516814598
##########
tests/tools/uranium/process.py:
##########
@@ -221,15 +221,36 @@ def stop(self, timeout: float = 5.0) -> None:
return_code = self._process.poll()
if return_code is None:
try:
- os.killpg(self._process.pid, signal.SIGTERM)
- self._process.wait(timeout=timeout)
- except ProcessLookupError:
- pass
+ if self.signal_group(signal.SIGTERM, timeout):
+ self._process.wait(timeout=timeout)
except subprocess.TimeoutExpired:
- os.killpg(self._process.pid, signal.SIGKILL)
- self._process.wait(timeout=timeout)
+ if self.signal_group(signal.SIGKILL, timeout):
+ self._process.wait(timeout=timeout)
self._close_streams()
+ def signal_group(self, signal_number: int, timeout: float = 5.0) -> bool:
+ """Send @a signal_number to the process group.
+
+ :param signal_number: Signal to send.
+ :param timeout: Seconds to wait for a leader that refuses the signal
because it is exiting.
+ :returns: False when the group had already exited, so there is nothing
to wait for.
+ """
+
+ if self._process is None:
+ raise ProcessError(f"{self.name} has not been started")
+ try:
+ os.killpg(self._process.pid, signal_number)
+ except ProcessLookupError:
+ return False
+ except PermissionError as error:
+ # Darwin fails with EPERM, not ESRCH, while the leader is exiting
or not yet reaped.
+ try:
+ self._process.wait(timeout=timeout)
+ except subprocess.TimeoutExpired:
+ raise error
+ return False
Review Comment:
Non-blocking: on Darwin, EPERM here means the leader is a zombie, but other
members of the group may still be running (for example, a child the service
spawned). After the leader is reaped this returns `False` without signaling
them, so they can outlive the test. Retrying `os.killpg(self._process.pid,
signal_number)` once after the `wait()` and ignoring `ProcessLookupError` would
cover that case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]