From b32fa0ef598178cc913ddacb9b1da4d1c3d07957 Mon Sep 17 00:00:00 2001 From: Lucas Meneghel Rodrigues Date: Tue, 12 Aug 2014 16:34:26 -0300 Subject: [PATCH] avocado.utils.process: Add new SubProcess API send_signal() Add send_signal(), that lets us to send arbitrary signals to subprocesses, and rewrite kill() and terminate() in terms of it. Signed-off-by: Lucas Meneghel Rodrigues --- avocado/utils/process.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/avocado/utils/process.py b/avocado/utils/process.py index 545accf7..f47d16f5 100644 --- a/avocado/utils/process.py +++ b/avocado/utils/process.py @@ -203,21 +203,23 @@ class SubProcess(object): """ Send a :attr:`signal.SIGTERM` to the process. """ - try: - os.kill(self.sp.pid, signal.SIGTERM) - except: - pass + self.send_signal(signal.SIGTERM) def kill(self): """ Send a :attr:`signal.SIGKILL` to the process. """ - try: - os.kill(self.sp.pid, signal.SIGKILL) - except: - pass + self.send_signal(signal.SIGKILL) - def wait(self, timeout=None): + def send_signal(self, sig): + """ + Send the specified signal to the process. + + :param sig: Signal to send. + """ + self.sp.send_signal(sig) + + def wait(self, timeout=None, sig=signal.SIGTERM): """ Wait for the process to end, filling and returning the result attr. @@ -243,7 +245,7 @@ class SubProcess(object): timeout = 1 if self.result.exit_status is None: - self.terminate() + self.send_signal(sig) # Timeout here should be 1 second (see comment above) stop_time = time.time() + timeout while time.time() < stop_time: -- GitLab