Python time.clock_gettime() Examples

The following are 24 code examples of time.clock_gettime(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module time , or try the search function .
Example #1
Source File: test_time.py    From android_universal with MIT License 6 votes vote down vote up
def test_time_ns_type(self):
        def check_ns(sec, ns):
            self.assertIsInstance(ns, int)

            sec_ns = int(sec * 1e9)
            # tolerate a difference of 50 ms
            self.assertLess((sec_ns - ns), 50 ** 6, (sec, ns))

        check_ns(time.time(),
                 time.time_ns())
        check_ns(time.monotonic(),
                 time.monotonic_ns())
        check_ns(time.perf_counter(),
                 time.perf_counter_ns())
        check_ns(time.process_time(),
                 time.process_time_ns())

        if hasattr(time, 'thread_time'):
            check_ns(time.thread_time(),
                     time.thread_time_ns())

        if hasattr(time, 'clock_gettime'):
            check_ns(time.clock_gettime(time.CLOCK_REALTIME),
                     time.clock_gettime_ns(time.CLOCK_REALTIME)) 
Example #2
Source File: test_time.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_monotonic_settime(self):
        t1 = time.monotonic()
        realtime = time.clock_gettime(time.CLOCK_REALTIME)
        # jump backward with an offset of 1 hour
        try:
            time.clock_settime(time.CLOCK_REALTIME, realtime - 3600)
        except PermissionError as err:
            self.skipTest(err)
        t2 = time.monotonic()
        time.clock_settime(time.CLOCK_REALTIME, realtime)
        # monotonic must not be affected by system clock updates
        self.assertGreaterEqual(t2, t1) 
Example #3
Source File: test_time.py    From android_universal with MIT License 5 votes vote down vote up
def test_clock_settime(self):
        t = time.clock_gettime(time.CLOCK_REALTIME)
        try:
            time.clock_settime(time.CLOCK_REALTIME, t)
        except PermissionError:
            pass

        if hasattr(time, 'CLOCK_MONOTONIC'):
            self.assertRaises(OSError,
                              time.clock_settime, time.CLOCK_MONOTONIC, 0) 
Example #4
Source File: test_time.py    From android_universal with MIT License 5 votes vote down vote up
def test_pthread_getcpuclockid(self):
        clk_id = time.pthread_getcpuclockid(threading.get_ident())
        self.assertTrue(type(clk_id) is int)
        self.assertNotEqual(clk_id, time.CLOCK_THREAD_CPUTIME_ID)
        t1 = time.clock_gettime(clk_id)
        t2 = time.clock_gettime(clk_id)
        self.assertLessEqual(t1, t2) 
Example #5
Source File: test_time.py    From android_universal with MIT License 5 votes vote down vote up
def test_clock_monotonic(self):
        a = time.clock_gettime(time.CLOCK_MONOTONIC)
        b = time.clock_gettime(time.CLOCK_MONOTONIC)
        self.assertLessEqual(a, b) 
Example #6
Source File: test_time.py    From android_universal with MIT License 5 votes vote down vote up
def test_clock_realtime(self):
        t = time.clock_gettime(time.CLOCK_REALTIME)
        self.assertIsInstance(t, float) 
Example #7
Source File: __init__.py    From grove.py with MIT License 5 votes vote down vote up
def set_mode(self, mode=MODE_SLEEP, t_sb=t_sb_1000):
        # Writes ctrl_meas register with current temperature and pressure oversampling settings
        # Only changes the mode
        # If normal mode selected also sets the standby time in config register

        # Set class variables
        self.mode = mode
        self.t_sb = t_sb

        # If no measurements are enabled there is no point going into measurement
        if self.osrs_t + self.osrs_p + self.osrs_h == 0:
            print("No measurement enabled!\nSee set_oversampling()-function to enable measurement.")
            return 0

        try:
            # If normal mode set also t_sb(standby time)
            if self.mode == self.MODE_NORMAL:
                # Write normal mode standby time t_sb to config register
                self.__config(t_sb, self.filter, self.spi3w_en)
                # Write mode to ctr_meas register
                self.__ctrl_meas(self.osrs_t, self.osrs_p, self.mode)
            # Otherwise just change the mode in ctrl_meas register
            else:
                self.__ctrl_meas(self.osrs_t, self.osrs_p, self.mode)

            self.last_meas = clock_gettime(CLOCK_REALTIME)
            # Everything went well return 1
            return 1
        except Exception as e:
            # e = sys.exc_info()[0]
            print("<p>Error: %s</p>" % e)
            return 0

    #########################################################################
    # Set oversampling/enable measurement. OVRS_x0 disables the measurement #
    ######################################################################### 
Example #8
Source File: test_time.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_monotonic_settime(self):
        t1 = time.monotonic()
        realtime = time.clock_gettime(time.CLOCK_REALTIME)
        # jump backward with an offset of 1 hour
        try:
            time.clock_settime(time.CLOCK_REALTIME, realtime - 3600)
        except PermissionError as err:
            self.skipTest(err)
        t2 = time.monotonic()
        time.clock_settime(time.CLOCK_REALTIME, realtime)
        # monotonic must not be affected by system clock updates
        self.assertGreaterEqual(t2, t1) 
Example #9
Source File: test_time.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_clock_settime(self):
        t = time.clock_gettime(time.CLOCK_REALTIME)
        try:
            time.clock_settime(time.CLOCK_REALTIME, t)
        except PermissionError:
            pass

        if hasattr(time, 'CLOCK_MONOTONIC'):
            self.assertRaises(OSError,
                              time.clock_settime, time.CLOCK_MONOTONIC, 0) 
Example #10
Source File: test_time.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_clock_monotonic(self):
        a = time.clock_gettime(time.CLOCK_MONOTONIC)
        b = time.clock_gettime(time.CLOCK_MONOTONIC)
        self.assertLessEqual(a, b) 
Example #11
Source File: test_time.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_clock_realtime(self):
        time.clock_gettime(time.CLOCK_REALTIME) 
Example #12
Source File: utils.py    From lpdec with GNU General Public License v3.0 5 votes vote down vote up
def clock():
        return time.clock_gettime(time.CLOCK_THREAD_CPUTIME_ID) 
Example #13
Source File: utils.py    From profiling with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def thread_clock():
        return time.clock_gettime(time.CLOCK_THREAD_CPUTIME_ID)


#: Does nothing.  It allows any arguments. 
Example #14
Source File: test_time.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_clock_settime(self):
        t = time.clock_gettime(time.CLOCK_REALTIME)
        try:
            time.clock_settime(time.CLOCK_REALTIME, t)
        except PermissionError:
            pass

        if hasattr(time, 'CLOCK_MONOTONIC'):
            self.assertRaises(OSError,
                              time.clock_settime, time.CLOCK_MONOTONIC, 0) 
Example #15
Source File: test_time.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_clock_monotonic(self):
        a = time.clock_gettime(time.CLOCK_MONOTONIC)
        b = time.clock_gettime(time.CLOCK_MONOTONIC)
        self.assertLessEqual(a, b) 
Example #16
Source File: test_time.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_clock_realtime(self):
        time.clock_gettime(time.CLOCK_REALTIME) 
Example #17
Source File: monotonic.py    From PySyncObj with MIT License 5 votes vote down vote up
def monotonic():
                """Monotonic clock, cannot go backward."""
                ts = timespec()
                if clock_gettime(CLOCK_MONOTONIC, ctypes.pointer(ts)):
                    errno = ctypes.get_errno()
                    raise OSError(errno, os.strerror(errno))
                return ts.tv_sec + ts.tv_nsec / 1.0e9

        # Perform a sanity-check. 
Example #18
Source File: ffmpeg_pipeline.py    From video-analytics-serving with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _set_real_base(self, metaconvert):
        self._real_base = int(
            time.clock_gettime(time.CLOCK_REALTIME) *
            FFmpegPipeline.SECONDS_TO_NANOSECONDS)

        if ("tags" not in self.request):
            self.request["tags"] = {}

        self.request["tags"]["real_base"] = self._real_base

        properties = self._video_filter_map[metaconvert].properties
        properties["tags"] = "\'{}\'".format(
            json.dumps(self.request["tags"]).replace(':', r'\:')) 
Example #19
Source File: test_time.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_monotonic_settime(self):
        t1 = time.monotonic()
        realtime = time.clock_gettime(time.CLOCK_REALTIME)
        # jump backward with an offset of 1 hour
        try:
            time.clock_settime(time.CLOCK_REALTIME, realtime - 3600)
        except PermissionError as err:
            self.skipTest(err)
        t2 = time.monotonic()
        time.clock_settime(time.CLOCK_REALTIME, realtime)
        # monotonic must not be affected by system clock updates
        self.assertGreaterEqual(t2, t1) 
Example #20
Source File: test_time.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_clock_settime(self):
        t = time.clock_gettime(time.CLOCK_REALTIME)
        try:
            time.clock_settime(time.CLOCK_REALTIME, t)
        except PermissionError:
            pass

        if hasattr(time, 'CLOCK_MONOTONIC'):
            self.assertRaises(OSError,
                              time.clock_settime, time.CLOCK_MONOTONIC, 0) 
Example #21
Source File: test_time.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_clock_monotonic(self):
        a = time.clock_gettime(time.CLOCK_MONOTONIC)
        b = time.clock_gettime(time.CLOCK_MONOTONIC)
        self.assertLessEqual(a, b) 
Example #22
Source File: test_time.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_clock_realtime(self):
        time.clock_gettime(time.CLOCK_REALTIME) 
Example #23
Source File: utils.py    From vulnix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __exit__(self, *exc):
        self.end = time.clock_gettime(time.CLOCK_MONOTONIC)
        self.interval = self.end - self.start
        _log.debug('<<< %s %.2fs', self.section, self.interval)
        return False  # re-raise 
Example #24
Source File: utils.py    From vulnix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __enter__(self):
        _log.debug('>>> %s', self.section)
        self.start = time.clock_gettime(time.CLOCK_MONOTONIC)
        return self