From 638e846024828759fdef213b431c87f796b1a814 Mon Sep 17 00:00:00 2001 From: Matthew Einhorn Date: Fri, 28 Aug 2015 16:08:59 -0400 Subject: [PATCH 1/2] Add clock to compat. --- kivy/compat.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 From af3308d6d9780f0231d884943a1f29ab6af714e6 Mon Sep 17 00:00:00 2001 From: Matthew Einhorn Date: Fri, 28 Aug 2015 16:13:08 -0400 Subject: [PATCH 2/2] Update clock.py to use compat's clock. --- kivy/clock.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/kivy/clock.py b/kivy/clock.py index ffbbc8f5a..7f67b1886 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,8 +239,6 @@ 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') @@ -252,14 +251,11 @@ try: def usleep(self, microseconds): _libc_usleep(int(microseconds)) - _default_time = time.time - except (OSError, ImportError): # ImportError: ctypes is not available on python-for-android. # OSError: if the libc cannot be readed (like with buildbot: invalid ELF # header) - _default_time = time.time _default_sleep = time.sleep class _ClockBase(object): @@ -641,8 +637,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):