Skip to content
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

Time is not freezed when using uvloop event loop #529

Open
serozhenka opened this issue Jan 4, 2024 · 0 comments
Open

Time is not freezed when using uvloop event loop #529

serozhenka opened this issue Jan 4, 2024 · 0 comments

Comments

@serozhenka
Copy link

serozhenka commented Jan 4, 2024

Description

freeze_time function doesn't freeze time when using asyncio with uvloop event loop.

uvloop's _time() uses uv_now() which is defined inside libuv here. From what I can see, you don't properly handle such a scenario and don't mock the time there.

Attaching simple script to reproduce:

import asyncio
from datetime import datetime, timezone

import uvloop
from freezegun import freeze_time


async def main():
    ts = datetime.now(timezone.utc)
    loop = asyncio.get_event_loop()
    print(loop.time())
    with freeze_time(ts):
        print(loop.time())


if __name__ == "__main__":
    asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
    asyncio.get_event_loop().run_until_complete(main())

Output:

334815.235
334815.248

Commenting the line with set_event_loop_policy yields the following result , which is the expected behaviour:

159228.968793708
1704377572.259583
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant