# HG changeset patch # User Oleg Oshmyan # Date 1298591988 0 # Node ID 741ae3391b61a862410c5502f16e1e7c71eef9f1 # Parent 953a5baa406dfce0ad1b9b4a3d7734f8b1891e90 Moved clock/time detection into platform-specific modules and testcases diff -r 953a5baa406d -r 741ae3391b61 problem.py --- a/problem.py Thu Feb 24 00:29:32 2011 +0000 +++ b/problem.py Thu Feb 24 23:59:48 2011 +0000 @@ -10,7 +10,7 @@ import __main__ __main__.import_error(sys.exc_info()[1]) else: - from __main__ import clock, options + from __main__ import options import os, re, sys diff -r 953a5baa406d -r 741ae3391b61 testcases.py --- a/testcases.py Thu Feb 24 00:29:32 2011 +0000 +++ b/testcases.py Thu Feb 24 23:59:48 2011 +0000 @@ -12,7 +12,7 @@ import __main__ __main__.import_error(sys.exc_info()[1]) else: - from __main__ import clock, options + from __main__ import options import glob, re, sys, tempfile, time from subprocess import Popen, PIPE, STDOUT @@ -20,6 +20,21 @@ import os devnull = open(os.path.devnull, 'w+') +if options.autotime: + # This is really a dirty hack that assumes that sleep() does not spend + # the CPU time of the current process and that if clock() measures + # wall-clock time, then it is more precise than time() is. Both these + # assumptions are true on all platforms I have tested this on so far, + # but I am not aware of any guarantee that they will both be true + # on every other platform. + c = time.clock() + time.sleep(1) + c = time.clock() - c + if int(c + .5) == 1: + clock = time.clock + else: + clock = time.time + try: from win32 import * except Exception: diff -r 953a5baa406d -r 741ae3391b61 unix.py --- a/unix.py Thu Feb 24 00:29:32 2011 +0000 +++ b/unix.py Thu Feb 24 23:59:48 2011 +0000 @@ -10,17 +10,24 @@ import __main__ __main__.import_error(sys.exc_info()[1]) -from __main__ import clock from subprocess import Popen import os, sys try: + from testcases import clock +except ImportError: + if sys.platform.startswith('java'): + from time import clock + else: + from time import time as clock + +try: from signal import SIGTERM, SIGKILL except ImportError: SIGTERM = 15 SIGKILL = 9 -__all__ = 'call', 'kill', 'terminate', 'pause' +__all__ = 'call', 'kill', 'terminate', 'pause', 'clock' if not sys.stdin.isatty(): diff -r 953a5baa406d -r 741ae3391b61 upreckon-vcs --- a/upreckon-vcs Thu Feb 24 00:29:32 2011 +0000 +++ b/upreckon-vcs Thu Feb 24 23:59:48 2011 +0000 @@ -64,25 +64,6 @@ if options.legacy: compat.pseudobuiltins += 'xrange', -if options.autotime: - # This is really a dirty hack that assumes that sleep() does not spend - # the CPU time of the current process and that if clock() measures - # wall-clock time, then it is more precise than time() is. Both these - # assumptions are true on all platforms I have tested this on so far, - # but I am not aware of any guarantee that they will both be true - # on every other platform. - c = time.clock() - time.sleep(1) - c = time.clock() - c - if int(c + .5) == 1: - clock = time.clock - else: - clock = time.time -elif sys.platform == 'win32': - clock = time.clock -else: - clock = time.time - try: import testcases except ImportError: diff -r 953a5baa406d -r 741ae3391b61 win32.py --- a/win32.py Thu Feb 24 00:29:32 2011 +0000 +++ b/win32.py Thu Feb 24 23:59:48 2011 +0000 @@ -14,7 +14,11 @@ from ctypes.wintypes import * from msvcrt import getch as pause from subprocess import Popen -from __main__ import clock + +try: + from testcases import clock +except ImportError: + from time import clock # Defaults that may be overwritten by values from _subprocess INFINITE = -1 @@ -43,7 +47,7 @@ else: ProcessTimes = namedtuple('ProcessTimes', 'kernel user') -__all__ = 'call', 'kill', 'terminate', 'pause' +__all__ = 'call', 'kill', 'terminate', 'pause', 'clock' # Automatically convert _subprocess handle objects into low-level HANDLEs