summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorerikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-11 20:45:24 +0000
committererikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-11 20:45:24 +0000
commite10a4f269949546f489ab84e23417717eeb9b70e (patch)
treee1c1a62db270b1b631e06a650a5df67143634dc7 /tools
parentc08d4794dbfb2f100cac2a54dec5c7f327ecddfa (diff)
downloadchromium_src-e10a4f269949546f489ab84e23417717eeb9b70e.zip
chromium_src-e10a4f269949546f489ab84e23417717eeb9b70e.tar.gz
chromium_src-e10a4f269949546f489ab84e23417717eeb9b70e.tar.bz2
Periodically log while waiting for subprocess to complete so that the bot doesn't kill us when we're taking a long time. Also clean up the subprocess wait loop.
BUG=7514 Review URL: http://codereview.chromium.org/20165 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9588 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
-rw-r--r--tools/purify/common.py63
1 files changed, 37 insertions, 26 deletions
diff --git a/tools/purify/common.py b/tools/purify/common.py
index d384514..b0b587c 100644
--- a/tools/purify/common.py
+++ b/tools/purify/common.py
@@ -58,9 +58,8 @@ def _print_line(line, flush=True):
sys.stdout.flush()
def RunSubprocess(proc, timeout=0, detach=False):
- """ Runs a subprocess, polling every .2 seconds until it finishes or until
- timeout is reached. Then kills the process with taskkill. A timeout <= 0
- means no timeout.
+ """ Runs a subprocess, until it finishes or |timeout| is exceeded and the
+ process is killed with taskkill. A |timeout| <= 0 means no timeout.
Args:
proc: list of process components (exe + args)
@@ -83,36 +82,48 @@ def RunSubprocess(proc, timeout=0, detach=False):
# necessary.
# TODO(erikkay): should we buffer stderr and stdout separately?
p = subprocess.Popen(proc, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
- if timeout <= 0:
- while p.poll() is None:
- if not detach:
- line = p.stdout.readline()
- while line:
- _print_line(line)
- line = p.stdout.readline()
- time.sleep(0.2)
- else:
+
+ # How long to wait (in seconds) before printing progress log messages.
+ progress_delay = 300
+ progress_delay_time = time.time() + progress_delay
+ did_timeout = False
+ if timeout > 0:
wait_until = time.time() + timeout
- while p.poll() is None and time.time() < wait_until:
- if not detach:
+ while p.poll() is None and not did_timeout:
+ if not detach:
+ line = p.stdout.readline()
+ while line:
+ _print_line(line)
line = p.stdout.readline()
- while line:
- _print_line(line)
- line = p.stdout.readline()
- time.sleep(0.2)
- if not detach:
- for line in p.stdout.readlines():
- _print_line(line, False)
- p.stdout.flush()
- result = p.poll()
- if result is None:
+ else:
+ # When we detach, blocking on reading stdout doesn't work, so we sleep
+ # a short time and poll.
+ time.sleep(0.5)
+ if time.time() >= progress_delay_time:
+ # Force output on a periodic basis to avoid getting killed off by the
+ # buildbot.
+ # TODO(erikkay): I'd prefer a less obtrusive 'print ".",' with a flush
+ # but because of how we're doing subprocesses, this doesn't appear to
+ # work reliably.
+ logging.info("%s still running..." % os.path.basename(proc[0]))
+ progress_delay_time = time.time() + progress_delay
+ if timeout > 0:
+ did_timeout = time.time() > wait_until
+
+ if did_timeout:
subprocess.call(["taskkill", "/T", "/F", "/PID", str(p.pid)])
logging.error("KILLED %d" % p.pid)
- # give the process a chance to actually die before continuing
- # so that cleanup can happen safely
+ # Give the process a chance to actually die before continuing
+ # so that cleanup can happen safely.
time.sleep(1.0)
logging.error("TIMEOUT waiting for %s" % proc[0])
raise TimeoutError(proc[0])
+ elif not detach:
+ for line in p.stdout.readlines():
+ _print_line(line, False)
+ p.stdout.flush()
+
+ result = p.poll()
if result:
logging.error("%s exited with non-zero result code %d" % (proc[0], result))
return result