changeset 304:02aff9ff8d24

Use time.monotonic() since Python now has it
author Matt Johnston <matt@ucc.asn.au>
date Wed, 24 Jul 2019 23:21:33 +0800
parents a99631597f65
children 6087c692d381
files py/tempserver.py py/utils.py
diffstat 2 files changed, 1 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/py/tempserver.py	Tue Jul 23 22:44:24 2019 +0800
+++ b/py/tempserver.py	Wed Jul 24 23:21:33 2019 +0800
@@ -68,7 +68,7 @@
             loop.close()
 
     def now(self):
-        return utils.monotonic_time()
+        return time.monotonic()
 
     def set_sensors(self, sensors):
         if hasattr(self, 'sensors'):
--- a/py/utils.py	Tue Jul 23 22:44:24 2019 +0800
+++ b/py/utils.py	Wed Jul 24 23:21:33 2019 +0800
@@ -21,37 +21,6 @@
     kwargs['exc_info'] = True
     logging.error(msg, *args, **kwargs)
 
-clock_gettime = None
-no_clock_gettime = True
-def monotonic_time():
-    global clock_gettime
-    global no_clock_gettime
-    if no_clock_gettime:
-        return time.time()
-
-    class timespec(ctypes.Structure):
-        _fields_ = [
-            ('tv_sec', ctypes.c_long),
-            ('tv_nsec', ctypes.c_long)
-        ]
-    if not clock_gettime:
-        try:
-            librt = ctypes.CDLL('librt.so.0', use_errno=True)
-            clock_gettime = librt.clock_gettime
-            clock_gettime.argtypes = [ctypes.c_int, ctypes.POINTER(timespec)]
-        except:
-            W("No clock_gettime(), using fake fallback.")
-            no_clock_gettime = True
-            return time.time()
-        
-    t = timespec()
-    CLOCK_MONOTONIC = 1 # see <linux/time.h>
-
-    if clock_gettime(CLOCK_MONOTONIC, ctypes.pointer(t)) != 0:
-        errno_ = ctypes.get_errno()
-        raise OSError(errno_, os.strerror(errno_))
-    return t.tv_sec + t.tv_nsec * 1e-9
-
 # decorator, tries a number of times, returns None on failure, sleeps between
 # Must be used as "@retry()" if arguments are defaulted
 def retry(retries=DEFAULT_TRIES, try_time = 1):