Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Unified Diff: client/bin/parallel.py

Issue 6883035: Merge remote branch 'autotest-upstream/master' into autotest-merge (Closed) Base URL: ssh://gitrw.chromium.org:9222/autotest.git@master
Patch Set: patch Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: client/bin/parallel.py
diff --git a/client/bin/parallel.py b/client/bin/parallel.py
index 47dd5cd9638b201b43229de83660c5fe51b6dd0f..647af753a51119e099d1533e6032430ec902b6ca 100644
--- a/client/bin/parallel.py
+++ b/client/bin/parallel.py
@@ -2,7 +2,7 @@
__author__ = """Copyright Andy Whitcroft 2006"""
-import sys, logging, os, pickle, traceback, gc
+import sys, logging, os, pickle, traceback, gc, time
from autotest_lib.client.common_lib import error, utils
def fork_start(tmp, l):
@@ -77,6 +77,35 @@ def fork_waitfor(tmp, pid):
raise error.TestError("Test subprocess failed rc=%d" % (status))
+def fork_waitfor_timed(tmp, pid, timeout):
+ """
+ Waits for pid until it terminates or timeout expires.
+ If timeout expires, test subprocess is killed.
+ """
+ timer_expired = True
+ poll_time = 2
+ time_passed = 0
+ while time_passed < timeout:
+ time.sleep(poll_time)
+ (child_pid, status) = os.waitpid(pid, os.WNOHANG)
+ if (child_pid, status) == (0, 0):
+ time_passed = time_passed + poll_time
+ else:
+ timer_expired = False
+ break
+
+ if timer_expired:
+ logging.info('Timer expired (%d sec.), nuking pid %d', timeout, pid)
+ utils.nuke_pid(pid)
+ (child_pid, status) = os.waitpid(pid, 0)
+ raise error.TestError("Test timeout expired, rc=%d" % (status))
+ else:
+ _check_for_subprocess_exception(tmp, pid)
+
+ if status:
+ raise error.TestError("Test subprocess failed rc=%d" % (status))
+
+
def fork_nuke_subprocess(tmp, pid):
utils.nuke_pid(pid)
_check_for_subprocess_exception(tmp, pid)

Powered by Google App Engine
This is Rietveld 408576698