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)
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
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)
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)
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)
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