当前位置: 首页>>代码示例>>Python>>正文


Python time.ticks_diff方法代码示例

本文整理汇总了Python中time.ticks_diff方法的典型用法代码示例。如果您正苦于以下问题:Python time.ticks_diff方法的具体用法?Python time.ticks_diff怎么用?Python time.ticks_diff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在time的用法示例。


在下文中一共展示了time.ticks_diff方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: publish

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_diff [as 别名]
def publish(self, topic, msg, retain=False, qos=0, timeout=None):
        task = None
        start = time.ticks_ms()
        while timeout is None or time.ticks_diff(time.ticks_ms(), start) < timeout:
            # Can't use wait_for because cancelling a wait_for would cancel _publishTimeout
            # Also a timeout in wait_for would cancel _publishTimeout without waiting for
            # the socket lock to be available, breaking mqtt protocol.
            if self._pub_task is None and task is None:
                task = asyncio.create_task(self._publishTimeout(topic, msg, retain, qos))
                self._pub_task = task
            elif task is not None:
                if self._pub_task != task:
                    return  # published
            await asyncio.sleep_ms(20)
        if task is not None:
            async with self.lock:
                task.cancel()
                return 
开发者ID:peterhinch,项目名称:micropython-mqtt,代码行数:20,代码来源:mqtt_as_timeout.py

示例2: check

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_diff [as 别名]
def check(self):
        current_time = time.ticks_ms()
        deadline = time.ticks_add(self.last_measurement, self.interval)
        if ((time.ticks_diff(deadline, current_time) <= 0) or (self.iterations == 0)):
            self.measure()
            self.iterations += 1
            self.last_measurement = current_time

# the following function, when added to the google sheet (Tools > Script editor) allows the
# formula uploaded in the "now" variable (see "measure(self)") to calculate a local timestamp
# from the epoch value loaded in column A of the inserted row
#
#function TIMESTAMP_TO_DATE(value) {
#  return new Date(value * 1000);
#}
# see the sheets.py file to set the ValueInputOption to USER_INPUT to avoid now string value being prefixed with a ' 
开发者ID:artem-smotrakov,项目名称:esp32-weather-google-sheets,代码行数:18,代码来源:weather.py

示例3: push_sorted

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_diff [as 别名]
def push_sorted(self, v, data):
        v.data = data

        if ticks_diff(data, ticks()) <= 0:
            cur = self.last
            if cur and ticks_diff(data, cur.data) >= 0:
                # Optimisation: can start looking from self.last to insert this item
                while cur.next and ticks_diff(data, cur.next.data) >= 0:
                    cur = cur.next
                v.next = cur.next
                cur.next = v
                self.last = cur
                return

        cur = self
        while cur.next and (not isinstance(cur.next.data, int) or ticks_diff(data, cur.next.data) >= 0):
            cur = cur.next
        v.next = cur.next
        cur.next = v
        if cur is not self:
            self.last = cur 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:23,代码来源:__init__.py

示例4: _loop

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_diff [as 别名]
def _loop(self):
        mqtt = config.getMQTT()
        mqtt.registerWifiCallback(self._wifiChanged)
        mqtt.registerConnectedCallback(self._reconnected)
        await self._flash(500, 1)
        sta = network.WLAN(network.STA_IF)
        st = time.ticks_ms()
        while True:
            while self._next:
                await self._flash(*self._next.pop(0))
                await asyncio.sleep(1)
            if time.ticks_diff(time.ticks_ms(), st) > 60000:  # heartbeat
                st = time.ticks_ms()
                if sta.isconnected():
                    await self._flash(20, 1)
                    await asyncio.sleep_ms(250)
                    await self._flash(20, 1)
                else:
                    await self._flash(500, 3)
            await asyncio.sleep_ms(500) 
开发者ID:kevinkk525,项目名称:pysmartnode,代码行数:22,代码来源:wifi_led.py

示例5: __bell

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_diff [as 别名]
def __bell(self):
        while True:
            await self._event_bell
            diff = time.ticks_diff(time.ticks_ms(), self._last_activation)
            if diff > 10000:
                _log.error("Bell rang {!s}s ago, not activated ringing".format(diff / 1000))
                self._event_bell.clear()
                return
            else:
                on = await _mqtt.publish(self.topic(), "ON", qos=1, timeout=2,
                                         await_connection=False)
                await asyncio.sleep_ms(self._on_time)
                await _mqtt.publish(self.topic(), "OFF", qos=1, retain=True, await_connection=on)
                if config.RTC_SYNC_ACTIVE:
                    t = time.localtime()
                    await _mqtt.publish(_mqtt.getDeviceTopic("last_bell"),
                                        "{}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}".format(t[0], t[1],
                                                                                       t[2], t[3],
                                                                                       t[4], t[5]),
                                        qos=1, retain=True, timeout=2, await_connection=False)
                self._event_bell.clear()
                if diff > 500:
                    _log.warn("Bell rang {!s}ms ago, activated ringing".format(diff)) 
开发者ID:kevinkk525,项目名称:pysmartnode,代码行数:25,代码来源:bell.py

示例6: overwatch

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_diff [as 别名]
def overwatch(coro_name, threshold, asyncr=False):
    def func_wrapper(coro):
        if asyncr is True:
            raise TypeError("overwatch does not support coroutines")
            # as it makes not sense. a freeze would trigger every coroutine
        else:
            def wrapper(*args, **kwargs):
                startt = time.ticks_ms()
                res = coro(*args, **kwargs)
                if str(type(res)) == "<class 'generator'>":
                    _log.error("Coroutine in sync overwatch")
                endt = time.ticks_ms()
                diff = time.ticks_diff(endt, startt)
                if diff > threshold:
                    _log.error("Coro {!s} took {!s}ms, threshold {!s}ms".format(coro_name, diff, threshold))
                return res

            return wrapper

    return func_wrapper 
开发者ID:kevinkk525,项目名称:pysmartnode,代码行数:22,代码来源:debug.py

示例7: timeit

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_diff [as 别名]
def timeit():
        spi = SpiMaster(1, baudrate=int(pyb.freq()[3] / 16))
        start = ticks_ms()

        for i in range(2 ** 10):
            spi.write_data(b'abcdefgh' * 4)
            spi.read_data()

        print("Millisecond ticks elapsed: %i" % ticks_diff(ticks_ms(), start)) 
开发者ID:SpotlightKid,项目名称:micropython-stm-lib,代码行数:11,代码来源:spimaster.py

示例8: _read_timeout

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_diff [as 别名]
def _read_timeout(cnt, timeout_ms=2000):
    time_support = "ticks_ms" in dir(time)
    s_time = time.ticks_ms() if time_support else 0
    data = sys.stdin.read(cnt)
    if len(data) != cnt or (time_support and time.ticks_diff(time.ticks_ms(), s_time) > timeout_ms):
        return None
    return data 
开发者ID:BetaRavener,项目名称:uPyLoader,代码行数:9,代码来源:download.py

示例9: ticks_diff

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_diff [as 别名]
def ticks_diff(new, old):
    if USE_UTIME:
        return time.ticks_diff(new, old)
    else:
        return new - old 
开发者ID:KMKfw,项目名称:kmk_firmware,代码行数:7,代码来源:kmktime.py

示例10: __init__

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_diff [as 别名]
def __init__(self, timediff):
        if timediff is None:
            self.expect_ts = False
            if is_micropython:
                self.timediff = lambda start, end : time.ticks_diff(start, end)/1000000
            else:
                raise ValueError('You must define a timediff function')
        else:
            self.expect_ts = True
            self.timediff = timediff
        self.start_time = None 
开发者ID:micropython-IMU,项目名称:micropython-fusion,代码行数:13,代码来源:deltat.py

示例11: TimeDiff

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_diff [as 别名]
def TimeDiff(start, end):
        return time.ticks_diff(start, end)/1000000 
开发者ID:micropython-IMU,项目名称:micropython-fusion,代码行数:4,代码来源:fusion_r_asyn.py

示例12: ppm

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_diff [as 别名]
def ppm(self, publish=True, timeout=5):
        if time.ticks_diff(time.ticks_ms(), self._time) > 5000:
            await self._read(publish, timeout)
        return self._ppm 
开发者ID:kevinkk525,项目名称:pysmartnode,代码行数:6,代码来源:ecMeter.py

示例13: _subscribeTopics

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_diff [as 别名]
def _subscribeTopics(self, start: int = 0):
        _log.debug("_subscribeTopics, start", start, local_only=True)
        try:
            for i, sub in enumerate(self._subs):
                # do not iter by range(start,length(_subs)) as _subs could get bigger while itering
                if i < start:
                    continue  # iter until start position reached
                t = sub[0]
                if self.isDeviceTopic(t):
                    t = self.getRealTopic(t)
                if len(sub) == 4:  # requested retained state topic
                    self._sub_retained = True
                    # if coro gets canceled in the process, the state topic will be checked
                    # the next time _subscribeTopic runs after the reconnect
                    _log.debug("_subscribing", t[:-4], local_only=True)
                    await self._preprocessor(super().subscribe, t[:-4], 1)  # subscribe state topic
                    ts = time.ticks_ms()  # start timer after successful subscribe otherwise
                    # it might time out before subscribe has even finished.
                    while time.ticks_diff(time.ticks_ms(), ts) < 4000 and self._sub_retained:
                        # wait 4 seconds for answer
                        await asyncio.sleep_ms(100)
                    if self._sub_retained is True:  # no state message received
                        self._subs[i] = sub[:3]
                        self._sub_retained = False
                        _log.debug("Unsubscribing state topic", t[:-4], "in _subsscribeTopics",
                                   local_only=True)
                        await self._preprocessor(super().unsubscribe, t[:-4],
                                                 await_connection=False)
                _log.debug("_subscribing", t, local_only=True)
                await self._preprocessor(super().subscribe, t, 1)
                # no timeouts because _subscribeTopics will get canceled when connection is lost
        finally:
            # remove pending unsubscribe requests
            for sub in self.__unsub_tmp:
                self._subs.remove(sub)
                self.__unsub_tmp = []
            self._sub_coro = None 
开发者ID:kevinkk525,项目名称:pysmartnode,代码行数:39,代码来源:mqtt.py

示例14: awaitSubscriptionsDone

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_diff [as 别名]
def awaitSubscriptionsDone(self, timeout=None, await_connection=True):
        start = time.ticks_ms()
        while timeout is None or time.ticks_diff(time.ticks_ms(), start) < timeout * 1000:
            if not await_connection and not self._isconnected:
                return False
            if self._sub_coro is None:
                return True  # all topics subscribed.
            await asyncio.sleep_ms(50)
        return False  # timeout 
开发者ID:kevinkk525,项目名称:pysmartnode,代码行数:11,代码来源:mqtt.py

示例15: _preprocessor

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_diff [as 别名]
def _preprocessor(self, coroutine, *args, timeout=None, await_connection=True):
        coro = None
        start = time.ticks_ms()
        i = 0 if len(args) == 4 else 1  # 0: publish, 1:(un)sub
        try:
            while timeout is None or time.ticks_diff(time.ticks_ms(), start) < timeout * 1000:
                if not await_connection and not self._isconnected:
                    return False
                if self._ops_coros[i] is coro is None:
                    coro = self._operationTimeout(coroutine, *args, i=i)
                    asyncio.get_event_loop().create_task(coro)
                    self._ops_coros[i] = coro
                elif coro:
                    if self._ops_coros[i] != coro:
                        return True  # published
                await asyncio.sleep_ms(20)
            _log.debug("timeout on", "(un)sub" if i else "publish", args, local_only=True)
            self.__timedout += 1
        except asyncio.CancelledError:
            raise  # the caller should be cancelled too
        finally:
            if coro and self._ops_coros[i] == coro:
                async with self.lock:
                    asyncio.cancel(coro)
                return False
            # else: returns value during process
        return False 
开发者ID:kevinkk525,项目名称:pysmartnode,代码行数:29,代码来源:mqtt.py


注:本文中的time.ticks_diff方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。