Added timeout to parallel subcommands.
Tested by running parallel tests for the following situations:
without timeout specified
with timeout specified and timing out
with timeout specified and not timing out
Signed-off-by: Colby Ranger <cranger@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@1176 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/server/utils.py b/server/utils.py
index 2dc7c90..9c534fb 100644
--- a/server/utils.py
+++ b/server/utils.py
@@ -145,6 +145,34 @@
time.sleep(1)
+def nuke_pid(pid):
+ # the process has not terminated within timeout,
+ # kill it via an escalating series of signals.
+ signal_queue = [signal.SIGTERM, signal.SIGKILL]
+ for sig in signal_queue:
+ try:
+ os.kill(pid, sig)
+
+ # The process may have died before we could kill it.
+ except OSError:
+ pass
+
+ try:
+ for i in range(5):
+ status = os.waitpid(pid, os.WNOHANG)[0]
+ if status == pid:
+ return
+ time.sleep(1)
+
+ if status != pid:
+ raise AutoservRunError('Could not kill pid %d'
+ % pid, None)
+
+ # the process died before we join it.
+ except OSError:
+ pass
+
+
def _process_output(pipe, fbuffer, teefile=None, use_os_read=True):
if use_os_read:
data = os.read(pipe.fileno(), 1024)