Mercurial > ~astiob > upreckon > hgweb
changeset 140:388ae061c915
The win32 module now trusts the wall-clock time reported by GetProcessTimes
author | Oleg Oshmyan <chortos@inbox.lv> |
---|---|
date | Tue, 24 May 2011 22:46:30 +0100 |
parents | 2d465a8a679c |
children | dfde0f5e0984 |
files | win32.py |
diffstat | 1 files changed, 21 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/win32.py Tue May 24 22:05:08 2011 +0100 +++ b/win32.py Tue May 24 22:46:30 2011 +0100 @@ -41,11 +41,12 @@ from operator import itemgetter class ProcessTimes(tuple): __slots__ = () - __new__ = lambda cls, kernel, user: tuple.__new__(cls, (kernel, user)) + def __new__(cls, creation, exit, kernel, user): + return tuple.__new__(cls, (creation, exit, kernel, user)) __getnewargs__ = lambda self: tuple(self) - kernel, user = (property(itemgetter(i)) for i in (0, 1)) + creation, exit, kernel, user = map(property, map(itemgetter, range(4))) else: - ProcessTimes = namedtuple('ProcessTimes', 'kernel user') + ProcessTimes = namedtuple('ProcessTimes', 'creation exit kernel user') __all__ = 'call', 'kill', 'pause', 'clock' @@ -177,10 +178,9 @@ else: def errcheck(result, func, args): if not result: raise WinError() - ftimes = [t.dwHighDateTime << 32 | t.dwLowDateTime for t in args[3:]] - kernel = ftimes[0] / 10000000 - user = ftimes[1] / 10000000 - return ProcessTimes(kernel, user) + times = ((t.dwHighDateTime << 32 | t.dwLowDateTime) / 10000000 + for t in args[1:]) + return ProcessTimes(*times) GetProcessTimes.errcheck = errcheck @@ -516,18 +516,25 @@ ir.Event.KeyEvent.wVirtualKeyCode == 27): raise testcases.CanceledByUser case.time_stopped = clock() - if GetProcessTimes and (case.maxcputime or not case.maxwalltime): + if GetProcessTimes: try: times = GetProcessTimes(case.process._handle) except WindowsError: pass else: - time = times.kernel + times.user - case.time_stopped = time - case.time_started = 0 - case.time_limit_string = case.cpu_time_limit_string - if case.maxcputime and time > case.maxcputime: - raise testcases.CPUTimeLimitExceeded + if case.maxcputime or not case.maxwalltime: + cputime = times.kernel + times.user + case.time_stopped = cputime + case.time_started = 0 + case.time_limit_string = case.cpu_time_limit_string + if case.maxcputime and cputime > case.maxcputime: + raise testcases.CPUTimeLimitExceeded + else: + case.time_stopped = times.exit + case.time_started = times.creation + walltime = times.exit - times.creation + if case.maxwalltime and walltime > case.maxwalltime: + raise testcases.WallTimeLimitExceeded if case.maxcputime and case.process.returncode == 1816: raise testcases.CPUTimeLimitExceeded if case.maxmemory and GetProcessMemoryInfo: