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


Python monotonic.monotonic方法代码示例

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


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

示例1: authenticate

# 需要导入模块: import monotonic [as 别名]
# 或者: from monotonic import monotonic [as 别名]
def authenticate(self):
        if self.expire_time is None or monotonic() > self.expire_time:  # first credential request, or the access token from the previous one expired
            # get an access token using OAuth
            credential_url = "https://api.cognitive.microsoft.com/sts/v1.0/issueToken"
            headers = {"Ocp-Apim-Subscription-Key": self.key}

            start_time = monotonic()
            response = self.session.post(credential_url, headers=headers)

            if response.status_code != 200:
                raise RequestError("http request error with status code {}".format(response.status_code))

            self.access_token = response.content
            expiry_seconds = 590 # document mentions the access token is expired in 10 minutes

            self.expire_time = start_time + expiry_seconds 
开发者ID:respeaker,项目名称:respeaker_python_library,代码行数:18,代码来源:bing_speech_api.py

示例2: wait_until

# 需要导入模块: import monotonic [as 别名]
# 或者: from monotonic import monotonic [as 别名]
def wait_until(action, description=None, exception_class=AssertionError, patience=60):
    """Attempt to call 'action' every 2 seconds, until it completes without exception or patience runs out"""
    __tracebackhide__ = True

    start = time_monotonic()
    cause = []
    if not description:
        description = action.__doc__ or action.__name__
    message = []
    while time_monotonic() < (start + patience):
        try:
            action()
            return
        except BaseException:
            cause = traceback.format_exception(*sys.exc_info())
        time.sleep(2)
    if cause:
        message.append("\nThe last exception was:\n")
        message.extend(cause)
    header = "Gave up waiting for {} after {} seconds at {}".format(description, patience,
                                                                    datetime.now().isoformat(" "))
    message.insert(0, header)
    raise exception_class("".join(message)) 
开发者ID:fiaas,项目名称:fiaas-deploy-daemon,代码行数:25,代码来源:utils.py

示例3: __wait_for

# 需要导入模块: import monotonic [as 别名]
# 或者: from monotonic import monotonic [as 别名]
def __wait_for(self, predicate, timeout=None):
        """
        Wait until a condition evaluates to True.

        predicate should be a callable which result will be interpreted as a
        boolean value.  A timeout may be provided giving the maximum time to
        wait.

        """
        endtime = None
        waittime = timeout
        result = predicate()
        while not result:
            if waittime is not None:
                if endtime is None:
                    endtime = _time() + waittime
                else:
                    waittime = endtime - _time()
                    if waittime <= 0:
                        break
            self.condition.wait(waittime)
            result = predicate()
        return result 
开发者ID:bk1285,项目名称:rpi_wordclock,代码行数:25,代码来源:event_handler.py

示例4: start

# 需要导入模块: import monotonic [as 别名]
# 或者: from monotonic import monotonic [as 别名]
def start(self):
        """Starts the watch (if not already started).

        NOTE(harlowja): resets any splits previously captured (if any).
        """
        if self._state == self._STARTED:
            return self
        self._started_at = monotonic.monotonic()
        self._state = self._STARTED
        return self 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:12,代码来源:utils.py

示例5: elapsed

# 需要导入模块: import monotonic [as 别名]
# 或者: from monotonic import monotonic [as 别名]
def elapsed(self):
        """Returns how many seconds have elapsed."""
        if self._state not in (self._STARTED, self._STOPPED):
            raise RuntimeError("Can not get the elapsed time of a stopwatch"
                               " if it has not been started/stopped")
        if self._state == self._STOPPED:
            elapsed = self._delta_seconds(self._started_at, self._stopped_at)
        else:
            elapsed = self._delta_seconds(
                self._started_at, monotonic.monotonic())
        return elapsed 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:13,代码来源:utils.py

示例6: stop

# 需要导入模块: import monotonic [as 别名]
# 或者: from monotonic import monotonic [as 别名]
def stop(self):
        """Stops the watch."""
        if self._state == self._STOPPED:
            return self
        if self._state != self._STARTED:
            raise RuntimeError("Can not stop a stopwatch that has not been"
                               " started")
        self._stopped_at = monotonic.monotonic()
        self._state = self._STOPPED
        return self 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:12,代码来源:utils.py

示例7: set

# 需要导入模块: import monotonic [as 别名]
# 或者: from monotonic import monotonic [as 别名]
def set(self, name, value, retries=3, wait_ready=False):
        if wait_ready:
            self.wait_ready()

        # TODO dumbly reimplement this using timeout loops
        # because we should actually be awaiting an ACK of PARAM_VALUE
        # changed, but we don't have a proper ack structure, we'll
        # instead just wait until the value itself was changed

        name = name.upper()
        # convert to single precision floating point number (the type used by low level mavlink messages)
        value = float(struct.unpack('f', struct.pack('f', value))[0])
        remaining = retries
        while True:
            self._vehicle._master.param_set_send(name, value)
            tstart = monotonic.monotonic()
            if remaining == 0:
                break
            remaining -= 1
            while monotonic.monotonic() - tstart < 1:
                if name in self._vehicle._params_map and self._vehicle._params_map[name] == value:
                    return True
                time.sleep(0.1)

        if retries > 0:
            self._logger.error("timeout setting parameter %s to %f" % (name, value))
        return False 
开发者ID:dronekit,项目名称:dronekit-python,代码行数:29,代码来源:__init__.py

示例8: mk_get_time

# 需要导入模块: import monotonic [as 别名]
# 或者: from monotonic import monotonic [as 别名]
def mk_get_time():
    """
    Create the best possible time function.
    """
    try:
        return time.perf_counter
    except AttributeError:
        import monotonic

        return monotonic.monotonic 
开发者ID:hynek,项目名称:prometheus-async,代码行数:12,代码来源:_utils.py

示例9: test_exec

# 需要导入模块: import monotonic [as 别名]
# 或者: from monotonic import monotonic [as 别名]
def test_exec(self):
        """
        Timer is a function and monotonic.
        """
        t1 = _utils.get_time()
        t2 = _utils.get_time()

        assert t1 < t2 
开发者ID:hynek,项目名称:prometheus-async,代码行数:10,代码来源:test_utils.py

示例10: test_py2

# 需要导入模块: import monotonic [as 别名]
# 或者: from monotonic import monotonic [as 别名]
def test_py2(self):
        """
        Use monotonic.time on Python 2
        """
        import monotonic

        assert _utils.get_time is monotonic.monotonic is _utils.mk_get_time() 
开发者ID:hynek,项目名称:prometheus-async,代码行数:9,代码来源:test_utils.py

示例11: generate_op_pre

# 需要导入模块: import monotonic [as 别名]
# 或者: from monotonic import monotonic [as 别名]
def generate_op_pre(self, op):
        # exop = self.exop
        # self.append("\n# {} pre", exop.name)
        # for input_decl in exop.input_decls:
        #     input_decl_name = 'a_'+input_decl.tensor.tensor_name
        #     self.append("#    arg {}", input_decl_name)
        # for output_decl in exop.output_decls:
        #     output_decl_name = 'a_'+output_decl.tensor.tensor_name
        #     self.append("#    output_decl {}", val_name)
        if is_tracing_enabled():
            self.append("self.__profiler_start__.append(monotonic())") 
开发者ID:NervanaSystems,项目名称:ngraph-python,代码行数:13,代码来源:cputransform.py

示例12: generate_op_post

# 需要导入模块: import monotonic [as 别名]
# 或者: from monotonic import monotonic [as 别名]
def generate_op_post(self, op):
        # exop = self.exop
        # self.append("print('{{}}'.format('{}'))", op.name)
        # for input_decl in exop.input.decls:
        #     input_decl_name = 'a_'+input_decl.tensor.tensor_name
        #     self.append("print('   arg {} = {{}}'.format({}))", input_decl_name, arg_name)
        # for val in exop.output_decls:
        #     output_decl_name = 'a_'+val.tensor.tensor_name
        #     self.append("#    output_decl {}", output_decl_name)
        #     self.append("print('   output_decl {} = {{}}'.format({}))", \
        #            output_decl_name, output_decl_name)
        if is_tracing_enabled():
            self.append("self.__profiler_stop__.append(monotonic())") 
开发者ID:NervanaSystems,项目名称:ngraph-python,代码行数:15,代码来源:cputransform.py

示例13: initialize_module

# 需要导入模块: import monotonic [as 别名]
# 或者: from monotonic import monotonic [as 别名]
def initialize_module(self, module):
        module.execute("""from __future__ import print_function
from builtins import print
import os
import numpy as np
import ctypes as ct
import numpy.ctypeslib as npct
import itertools as itt
from monotonic import monotonic as monotonic
from ngraph.op_graph import axes
from ngraph.transformers.cpu.cpuengine import fprop_lut, update_lut
from ngraph.transformers.cpu.cpuengine import Mkldnn
from ngraph.transformers.cpu.cpuengine import ConvLocals
from ngraph.transformers.cpu.ctc import ctc_cpu
from ngraph.transformers.cputransform import align_ndarray
        """)

        if use_mlsl:
            module.execute("""
from ngraph.transformers.cpu.hetr import HetrLocals
            """)

        mkldnn_path = os.path.join(os.path.dirname(__file__), "..", "..")
        mkldnn_engine_path = os.path.join(mkldnn_path, 'mkldnn_engine.so')
        module.execute("mkldnn = Mkldnn(r'{}')".format(mkldnn_engine_path))
        module.execute("mkldnn.open()")
        self.mkldnn = module['mkldnn'] 
开发者ID:NervanaSystems,项目名称:ngraph-python,代码行数:29,代码来源:cputransform.py

示例14: Get

# 需要导入模块: import monotonic [as 别名]
# 或者: from monotonic import monotonic [as 别名]
def Get(self, block=True, timeout=None):
        if sys.version[0] == '2' and block:
            if timeout:
                timeout += monotonic.monotonic()
            # If timeout is None, then just pick some arbitrarily large # for the timeout value.
            else:
                timeout = 1000000 + monotonic.monotonic()

            while True:
                try:
                    # Allow check for Ctrl-C every second
                    item = self.queue.get(timeout=min(1, timeout - monotonic.monotonic()))
                    self.queue.task_done()
                    return item
                except queue.Empty:
                    if monotonic.monotonic() > timeout:
                        return None
                    else:
                        pass
        else:
            try:
                item = self.queue.get(block=block, timeout=timeout)
                self.queue.task_done()
                return item
            except queue.Empty as e:
                return None
            except Exception as e:
                return None 
开发者ID:jeffreydwalter,项目名称:arlo,代码行数:30,代码来源:eventstream.py

示例15: assert_eventlet_uses_monotonic_clock

# 需要导入模块: import monotonic [as 别名]
# 或者: from monotonic import monotonic [as 别名]
def assert_eventlet_uses_monotonic_clock():
    import eventlet.hubs as hubs
    import monotonic

    hub = hubs.get_hub()
    if hub.clock is not monotonic.monotonic:
        raise RuntimeError(
            'eventlet hub is not using a monotonic clock - '
            'periodic tasks will be affected by drifts of system time.') 
开发者ID:openstack,项目名称:masakari,代码行数:11,代码来源:service.py


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