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


Python trio.current_time方法代码示例

本文整理汇总了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) 
开发者ID:ethereum,项目名称:trinity,代码行数:19,代码来源:test_trio_utils.py

示例2: time

# 需要导入模块: import trio [as 别名]
# 或者: from trio import current_time [as 别名]
def time() -> float:
        return trio.current_time() 
开发者ID:pgjones,项目名称:hypercorn,代码行数:4,代码来源:context.py

示例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)) 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:15,代码来源:monitor.py

示例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) 
开发者ID:ziirish,项目名称:burp-ui,代码行数:12,代码来源:monitor.py

示例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) 
开发者ID:HyperionGray,项目名称:starbelly,代码行数:10,代码来源:__init__.py

示例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_ 
开发者ID:HyperionGray,项目名称:starbelly,代码行数:12,代码来源:test_schedule.py

示例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 
开发者ID:HyperionGray,项目名称:starbelly,代码行数:13,代码来源:test_schedule.py

示例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 
开发者ID:HyperionGray,项目名称:starbelly,代码行数:33,代码来源:rate_limiter.py

示例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)) 
开发者ID:HyperionGray,项目名称:starbelly,代码行数:14,代码来源:rate_limiter.py

示例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 
开发者ID:HyperionGray,项目名称:starbelly,代码行数:28,代码来源:resource_monitor.py

示例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() 
开发者ID:s3ql,项目名称:s3ql,代码行数:8,代码来源:mount.py

示例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)) 
开发者ID:s3ql,项目名称:s3ql,代码行数:5,代码来源:mount.py

示例13: current_time

# 需要导入模块: import trio [as 别名]
# 或者: from trio import current_time [as 别名]
def current_time():
    return trio.current_time() 
开发者ID:ethereum,项目名称:trinity,代码行数:4,代码来源:conftest.py

示例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) 
开发者ID:ethereum,项目名称:trinity,代码行数:5,代码来源:conftest.py

示例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 
开发者ID:ethereum,项目名称:trinity,代码行数:7,代码来源:conftest.py


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