Ejemplo n.º 1
0
def ceil_timeout(delay: Optional[float]) -> async_timeout.Timeout:
    if delay is not None:
        loop = get_running_loop()
        now = loop.time()
        return async_timeout.timeout_at(ceil(now + delay))
    else:
        return async_timeout.timeout(None)
Ejemplo n.º 2
0
async def test_timeout_at() -> None:
    loop = asyncio.get_event_loop()
    with pytest.raises(asyncio.TimeoutError):
        now = loop.time()
        async with timeout_at(now + 0.01) as cm:
            await asyncio.sleep(10)
    assert cm.expired
Ejemplo n.º 3
0
async def test_shift_to_expired() -> None:
    loop = asyncio.get_event_loop()
    t0 = loop.time()
    async with timeout_at(t0 + 0.001) as cm:
        with pytest.raises(asyncio.CancelledError):
            await asyncio.sleep(10)
        with pytest.raises(RuntimeError,
                           match="cannot reschedule expired timeout"):
            cm.update(t0 + 10)
Ejemplo n.º 4
0
def ceil_timeout(delay: Optional[float]) -> async_timeout.Timeout:
    if delay is None or delay <= 0:
        return async_timeout.timeout(None)

    loop = asyncio.get_running_loop()
    now = loop.time()
    when = now + delay
    if delay > 5:
        when = ceil(when)
    return async_timeout.timeout_at(when)
Ejemplo n.º 5
0
def ceil_timeout(delay: Optional[float]) -> async_timeout.Timeout:
    if delay is not None and delay > 0:
        loop = get_running_loop()
        now = loop.time()
        when = now + delay
        if delay > 5:
            when = ceil(when)
        return async_timeout.timeout_at(when)
    else:
        return async_timeout.timeout(None)
Ejemplo n.º 6
0
async def test_timeout_at_not_fired() -> None:
    loop = asyncio.get_event_loop()
    now = loop.time()
    async with timeout_at(now + 1) as cm:
        await asyncio.sleep(0)
    assert not cm.expired