Let callers override the 20-second context-exit timeout for long-running commands. None waits indefinitely on normal exit, but gives a readiness-enabled command one second to exit on cancellation. An explicit zero still means no grace period. Signed-off-by: Rishikesh Jethwani --- tools/testing/selftests/net/lib/py/utils.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py index 9edfc4f88621..1db7a21db642 100644 --- a/tools/testing/selftests/net/lib/py/utils.py +++ b/tools/testing/selftests/net/lib/py/utils.py @@ -274,7 +274,11 @@ class cmd: if self.proc.poll() is None: if terminate: self._kill_group(signal.SIGTERM) - self._drain_until_exit((out, err), timeout=timeout) + # None waits forever elsewhere; cleanup must end. Not + # "timeout or 1", which would change an explicit 0. + self._drain_until_exit((out, err), + timeout=1 if timeout is None + else timeout) self._collect_reaped(out, err) def _collect_reaped(self, out, err): @@ -385,11 +389,12 @@ class bkg(cmd): """ def __init__(self, comm, shell=None, fail=None, expect_fail=None, ns=None, host=None, exit_wait=False, ksft_ready=None, - ksft_wait=None): + ksft_wait=None, timeout=20): super().__init__(comm, background=True, shell=shell, fail=fail, expect_fail=expect_fail, ns=ns, host=host, ksft_ready=ksft_ready, ksft_wait=ksft_wait) + self.timeout = timeout self.terminate = not exit_wait and not ksft_wait self._exit_wait = exit_wait self.check_fail = fail @@ -410,15 +415,18 @@ class bkg(cmd): terminate = terminate or (self._exit_wait and ex_type is not None) if ex_type is None: return self.process(terminate=terminate, fail=self.check_fail, - expect_fail=self.expect_fail) + expect_fail=self.expect_fail, + timeout=self.timeout) # Cancelled, e.g. by Ctrl-C: stop the command and what it started, # without replacing the exception in flight. if self._own_pgrp: - self._cleanup_quietly(self._reap_cancelled, terminate, 20) + self._cleanup_quietly(self._reap_cancelled, terminate, + self.timeout) else: self._cleanup_quietly(self.process, terminate=terminate, fail=self.check_fail, - expect_fail=self.expect_fail) + expect_fail=self.expect_fail, + timeout=self.timeout) return None -- 2.50.1