本文整理汇总了Python中trio.current_time方法的典型用法代码示例。如果您正苦于以下问题:Python trio.current_time方法的具体用法?Python trio.current_time怎么用?Python trio.current_time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trio
的用法示例。
在下文中一共展示了trio.current_time方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_every
# 需要导入模块: import trio [as 别名]
# 或者: from trio import current_time [as 别名]
def test_every(autojump_clock):
start_time = trio.current_time()
every_generator = every(2, initial_delay=1)
first_time = await every_generator.__anext__()
assert first_time == pytest.approx(trio.current_time())
assert first_time <= trio.current_time()
assert first_time == pytest.approx(start_time + 1)
second_time = await every_generator.__anext__()
assert second_time == pytest.approx(trio.current_time())
assert second_time == pytest.approx(first_time + 2)
third_time = await every_generator.__anext__()
assert third_time == pytest.approx(trio.current_time())
assert third_time == pytest.approx(first_time + 4)
示例2: time
# 需要导入模块: import trio [as 别名]
# 或者: from trio import current_time [as 别名]
def time() -> float:
return trio.current_time()
示例3: task_exited
# 需要导入模块: import trio [as 别名]
# 或者: from trio import current_time [as 别名]
def task_exited(self, task):
del self._tasks[id(task)]
# def before_io_wait(self, timeout):
# if timeout:
# print("### waiting for I/O for up to {} seconds".format(timeout))
# else:
# print("### doing a quick check for I/O")
# self._sleep_time = trio.current_time()
# def after_io_wait(self, timeout):
# duration = trio.current_time() - self._sleep_time
# print("### finished I/O check (took {} seconds)".format(duration))
示例4: get_mon
# 需要导入模块: import trio [as 别名]
# 或者: from trio import current_time [as 别名]
def get_mon(self, ident) -> Monitor:
self.logger.info(f'{ident} - Waiting for a monitor...')
t1 = trio.current_time()
mon = await self.pool.get() # type: Monitor
t2 = trio.current_time()
t = t2 - t1
self.logger.info(f'{ident} - Waited {t:.3f}s')
yield mon
self.logger.info(f'{ident} - Releasing monitor')
await self.pool.put(mon)
示例5: assert_min_elapsed
# 需要导入模块: import trio [as 别名]
# 或者: from trio import current_time [as 别名]
def assert_min_elapsed(seconds):
'''
Fail the test if the execution of a block takes less than ``seconds``.
'''
start = trio.current_time()
yield
elapsed = trio.current_time() - start
assert elapsed >= seconds, 'Completed in under {} seconds'.format(seconds)
示例6: assert_elapsed
# 需要导入模块: import trio [as 别名]
# 或者: from trio import current_time [as 别名]
def assert_elapsed(min_=None, max_=None):
''' A context manager which asserts that its block runs within some bounded
time. '''
start = trio.current_time()
yield
elapsed = trio.current_time() - start
if min_ is not None:
assert elapsed >= min_
if max_ is not None:
assert elapsed <= max_
示例7: test_event_order
# 需要导入模块: import trio [as 别名]
# 或者: from trio import current_time [as 别名]
def test_event_order():
# This test is async because it relies on the Trio clock.
schedule = make_schedule(1)
due_future = trio.current_time() + 60
due_past = trio.current_time() - 60
due_now = trio.current_time()
dues = [due_future, due_past, due_now]
dues.sort()
assert dues[0] == due_past
assert dues[1] == due_now
assert dues[2] == due_future
示例8: _get_next_expiry
# 需要导入模块: import trio [as 别名]
# 或者: from trio import current_time [as 别名]
def _get_next_expiry(self):
'''
Pop an expiry off the heap.
If no tokens on heap, suspend until a token is available.
:returns: The next expiry.
:rtype: Expiry
'''
while True:
if not self._expires:
# If there are no pending expirations, then we wait for a new
# token or a reset of an existing token.
with trio.CancelScope() as cancel_scope:
self._expiry_cancel_scope = cancel_scope
await trio.sleep_forever()
continue
# Now there are definitely pending expirations. Examine the earliest
# pending expiration. If it is in the past, then we pop it
# immediately. If it is in the future, then sleep until its
# expiration time or until somebody adds or resets a token.
now = trio.current_time()
expires = self._expires[0].time
if expires <= now:
expiry = heappop(self._expires)
return expiry
with trio.move_on_after(expires - now) as cancel_scope:
self._expiry_cancel_scope = cancel_scope
await trio.sleep_forever()
continue
示例9: _read_resets_task
# 需要导入模块: import trio [as 别名]
# 或者: from trio import current_time [as 别名]
def _read_resets_task(self):
'''
This task listens for incoming resets that indicate that a request has
finished downloading and its corresponding rate limit should start.
:returns: This task runs until cancelled.
'''
async for url in self._reset_recv:
logger.debug('Reset URL: %s', url)
token = get_domain_token(url.host)
limit = self._rate_limits.get(token, self._global_limit)
self._add_expiry(Expiry(trio.current_time() + limit, token))
示例10: run
# 需要导入模块: import trio [as 别名]
# 或者: from trio import current_time [as 别名]
def run(self):
'''
Run the resource monitor.
:returns: Runs until cancelled.
'''
next_run = trio.current_time() + self._interval
while True:
measurement = self._measure()
self._measurements.append(measurement)
to_remove = set()
for channel in self._channels:
try:
channel.send_nowait(measurement)
except trio.WouldBlock:
continue
except trio.BrokenResourceError:
to_remove.add(channel)
for channel in to_remove:
logger.debug('Removing closed channel')
self._channels.remove(channel)
sleep_time = next_run - trio.current_time()
while sleep_time < 0:
sleep_time += self._interval
await trio.sleep(sleep_time)
next_run += self._interval
示例11: before_io_wait
# 需要导入模块: import trio [as 别名]
# 或者: from trio import current_time [as 别名]
def before_io_wait(self, timeout):
if timeout:
print("### waiting for I/O for up to {} seconds".format(timeout))
else:
print("### doing a quick check for I/O")
self._sleep_time = trio.current_time()
示例12: after_io_wait
# 需要导入模块: import trio [as 别名]
# 或者: from trio import current_time [as 别名]
def after_io_wait(self, timeout):
duration = trio.current_time() - self._sleep_time
print("### finished I/O check (took {} seconds)".format(duration))
示例13: current_time
# 需要导入模块: import trio [as 别名]
# 或者: from trio import current_time [as 别名]
def current_time():
return trio.current_time()
示例14: genesis_time
# 需要导入模块: import trio [as 别名]
# 或者: from trio import current_time [as 别名]
def genesis_time(current_time, eth2_config):
slots_after_genesis = 10
return int(current_time - slots_after_genesis * eth2_config.SECONDS_PER_SLOT)
示例15: get_trio_time
# 需要导入模块: import trio [as 别名]
# 或者: from trio import current_time [as 别名]
def get_trio_time():
def _f():
return trio.current_time()
return _f