achimnol / aiotools

Idiomatic asyncio utilties
https://aiotools.readthedocs.io
MIT License
153 stars 11 forks source link

Eventloop get stuck when VirtualClock used with real timestamps #69

Open KholdStare opened 6 months ago

KholdStare commented 6 months ago

When using real timestamps for like 1709591365, the python event loop gets stuck forever in await:

import pytest
import asyncio
from aiotools import VirtualClock

@pytest.mark.asyncio
async def test_stuck_forever():
  clock = VirtualClock()
  clock.vtime = 1709591365
  with lock.patch_loop():
    await asyncio.sleep(1)

This is due to a behavior (bug?) in the BaseEventLoop https://github.com/python/cpython/issues/116342 .

The way I was able to solve it, was to override the eventloop _clock_resolution to 0.1 . Perhaps this should be added to the patch_loop implementation?