Bug 782598 - part 2: tidy get_max_wait() r=terrence

This commit is contained in:
Jon Coppeard 2012-08-15 12:02:09 +01:00
parent 22e2e9b15a
commit d7afbafc7e
2 changed files with 18 additions and 18 deletions

View File

@ -1,7 +1,7 @@
# Text progress bar library, like curl or scp.
import sys
from datetime import datetime
from datetime import datetime, timedelta
if sys.platform.startswith('win'):
from lib.terminal_win import Terminal
@ -13,6 +13,7 @@ class NullProgressBar(object):
def poke(self): pass
def finish(self, complete=True): pass
def message(self, msg): sys.stdout.write(msg + '\n')
def update_granularity(self): return timedelta.max
class ProgressBar(object):
def __init__(self, limit, fmt):
@ -33,6 +34,9 @@ class ProgressBar(object):
self.barlen = 64 - self.counters_width
def update_granularity(self):
return timedelta(seconds=0.1)
def update(self, current, data):
# Record prior for poke.
self.prior = (current, data)

View File

@ -6,8 +6,6 @@ import errno, os, sys, select
from datetime import datetime, timedelta
from results import TestOutput
PROGRESS_BAR_GRANULARITY = 0.1 #sec
class Task(object):
def __init__(self, test, pid, stdout, stderr):
self.test = test
@ -52,24 +50,22 @@ def get_max_wait(tasks, results, timeout):
"""
Return the maximum time we can wait before any task should time out.
"""
now = datetime.now()
wait = timedelta(0)
for task in tasks:
remaining = timedelta(seconds=timeout) - (now - task.start)
if remaining > wait:
wait = remaining
wait = total_seconds(wait)
# The test harness uses a timeout of 0 to indicate we should wait forever,
# but for select(), a timeout of 0 indicates a zero-length wait. Instead,
# translate the timeout into None to tell select to wait forever.
if wait == 0:
return None
# If we have a progress-meter, we need to wake up to update it frequently.
wait = min(wait, PROGRESS_BAR_GRANULARITY)
wait = results.pb.update_granularity()
return wait
# If a timeout is supplied, we need to wake up for the first task to
# timeout if that is sooner.
if timeout:
now = datetime.now()
timeout_delta = timedelta(seconds=timeout)
for task in tasks:
remaining = task.start + timeout_delta - now
if remaining < wait:
wait = remaining
# Return the wait time in seconds, clamped to zero.
return max(total_seconds(wait), 0)
def flush_input(fd, frags):
"""