本文整理匯總了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
示例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))
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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()
示例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())")
示例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())")
示例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']
示例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
示例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.')