當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。