Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34.2k
gh-145703: Fix asyncio.BaseEventLoop low clock resolution#145706
gh-145703: Fix asyncio.BaseEventLoop low clock resolution#145706CaptainFlint wants to merge 6 commits intopython:mainfrom
Conversation
asyncio event loop uses monotonic timer which in many systems is the OS uptime.With low enough clock resolution (often being 1e-09) and high enough uptime(~194 days), adding the "clock tick" to the current time hits the floatingpoint precision limits and does not change the time value.The comparison then returns invalid result, and tasks scheduled to trigger atthis exact moment are not triggered. They will be triggered only later, at thenext call.This commit fixes the issue by making sure the "next tick" is adjusted to thecurrent time's floating point precision. Therefore, end_time is guaranteed tobe incremented.
Uh oh!
There was an error while loading.Please reload this page.
Misc/NEWS.d/next/Library/2026-03-09-19-59-05.gh-issue-145703.4EEP7J.rst OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
* Fixed sorting of imports* Fixed formatting in the NEWS entry* Reworded the explanatory comment
picnixz commentedMar 9, 2026
Oh so |
CaptainFlint commentedMar 9, 2026
I found an existing reference to |
picnixz commentedMar 9, 2026
If there are other methods that are affected by that, you can also mention them (I actually don't know if it's used by call_soon, I just assumed so because it's about callbacks) |
CaptainFlint commentedMar 9, 2026
Well, the code that triggered the issue for me was using I can't tell whether I think, then, it's better to mention only |
Misc/NEWS.d/next/Library/2026-03-09-19-59-05.gh-issue-145703.4EEP7J.rst OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
picnixz left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'm not an asyncio expert so I'll leave it for the maintainers but this looks like the best alternative.
CaptainFlint commentedMar 9, 2026
Thanks a lot for your input and help! I really appreciate it! |
Uh oh!
There was an error while loading.Please reload this page.
With this fix we make sure that even if the clock resolution becomes too small, the "next tick" will still be different from the current time, and the comparison remains valid.
Example: clock resolution = 1e-9, current uptime = 200 days (17280000 seconds). Floating point addition does not change the value, because the precision is too small. In this case the patch will use
math.ulp(), which is the smallest possible increment that will modify the current value.