-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Discussion] about freezing asyncio #521
Comments
This also breaks compatibility with pytest-socket. When using freezegun now, even without any use of asyncio, freezegun triggers an asyncio event loop and this in turn tries to use a socket, which
Since we aren't even using asyncio at all, this is very confusing behaviour. Would it be possible to add a flag or config to freezegun to prevent it from starting asyncio, and thus prevent it from using socket? |
My argument would be that users of freezegun who don't use asyncio should not need to opt-out of asyncio - it is unfortunate that freezegun creates an event loop even when the user does not use or wish to use asyncio. However, there seems to be no reliable way to determine if asyncio is in use, and even the It appears that pytest-socket has their own asyncio workaround, |
Even when using Passing tests with freezegun 1.2.2: https://github.com/wimglenn/advent-of-code-data/actions/runs/7123359485/job/19395845855 I encountered this in wimglenn/advent-of-code-data#130 - all other pieces held constant, apart from adding the "freezegun < 1.3" constraint. Note: the project under test does not use asyncio at all. |
Ah yes, on windows asyncio doesn't use unix sockets / the unix selector, so there is no workaround there as far as I know. |
I think one of the main reason of the original mr was is that freeze_time does not freeze However, Wouldn't it make sense for a non-ticking freeze_time to also freeze |
The 1.3.0 behaviour is now hidden behind a feature-flag, so
This is part of the 1.4.0 release. |
PR #470 basically unfroze asyncio during freeze_time.
Although i understand the need for it (not breaking tests that perform real waits on real events), it breaks the main purpose of freeze_time: Asyncio is no-longer frozen even without tick and i can no longer trigger events that would happen in an asyncio future without waiting the full duration( for instance, a common pattern is to do asyncio.sleep(remaining_time)). This makes some tests that were instant have to wait for whole timeout instead with freezegun>=1.3.0.
I understand that both properties may be desirable, but, the first one should only work with tick=True (it is currently inconditional), and may still manipulate monotonic for asyncio (it is desirable to trigger futures events with freezegun).
A switch to get one behaviour or another may be needed; i guess there are even case where monotonic and time may need to be handled in a completely othogonal manner (as manipulating monotonic will always end up breaking a fundamental promise of the api: being monotonic).
So should i make a PR to make this behavior opt-in ? Add a new switch for asyncio ?
(Note, i have a longer take on this on a similar (but note quite the same) issue in time-machine: adamchainz/time-machine#406)
The text was updated successfully, but these errors were encountered: