diff --git a/kivy/clock.py b/kivy/clock.py index 01f9b6c2e..823c277db 100644 --- a/kivy/clock.py +++ b/kivy/clock.py @@ -216,6 +216,7 @@ from kivy.context import register_context from kivy.weakmethod import WeakMethod from kivy.config import Config from kivy.logger import Logger +from kivy.compat import clock as _default_time import time try: @@ -238,12 +239,9 @@ try: self._timer, ctypes.byref(delay), 0, ctypes.c_void_p(), ctypes.c_void_p(), False) _kernel32.WaitForSingleObject(self._timer, 0xffffffff) - - _default_time = time.clock else: if platform == 'darwin': _libc = ctypes.CDLL('libc.dylib') - _default_time = time.time else: from ctypes.util import find_library _libc = ctypes.CDLL(find_library('c'), use_errno=True) @@ -291,7 +289,6 @@ except (OSError, ImportError, AttributeError): # OSError: if the libc cannot be readed (like with buildbot: invalid ELF # header) - _default_time = time.time _default_sleep = time.sleep class _ClockBase(object): @@ -673,8 +670,7 @@ class ClockBase(_ClockBase): time = staticmethod(partial(_default_time)) -ClockBase.time.__doc__ = '''Proxy method for time.time() or time.clock(), -whichever is more suitable for the running OS''' +ClockBase.time.__doc__ = '''Proxy method for :func:`~kivy.compat.clock`. ''' def mainthread(func): diff --git a/kivy/compat.py b/kivy/compat.py index 93c470fb7..a163014c3 100644 --- a/kivy/compat.py +++ b/kivy/compat.py @@ -7,6 +7,7 @@ __all__ = ('PY2', 'string_types', 'queue', 'iterkeys', 'itervalues', 'iteritems') import sys +import time try: import queue except ImportError: @@ -14,6 +15,10 @@ except ImportError: #: True if Python 2 intepreter is used PY2 = sys.version_info[0] == 2 +'''True, if the version of python running is 2.x. ''' + +clock = None +'''A clock with the highest available resolution. ''' #: String types that can be used for checking if a object is a string string_types = None @@ -38,3 +43,12 @@ else: iterkeys = lambda d: iter(d.keys()) itervalues = lambda d: iter(d.values()) iteritems = lambda d: iter(d.items()) + + +if PY2: + if sys.platform in ('win32', 'cygwin'): + clock = time.clock + else: + clock = time.time +else: + clock = time.perf_counter