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
GH-75720: use time.perf_counter in asyncio loop.time()
#97027
Conversation
kumaraditya303
commented
Sep 22, 2022
•
edited by bedevere-bot
edited by bedevere-bot
- Issue: asyncio.sleep may sleep less time then it should #75720
|
If you want to schedule another build, you need to add the " |
|
I’m asking for a buildbot test so we’ll know if any exotic systems have weird or broken perf timers. |
|
A concern I have is, are there systems whose perf timer wraps around within the lifetime of a typical server? That would be a problem… |
|
See also #88494 |
Changing time.monotonic() on Windows to use a clock with a better resolution is discussed in #88494 which explains why it was not done yet. |
Okay so all buildbots have passed so that's good.
As explained on discord, this isn't a problem as there are no wrapping around issues. |
This PR is about changing asyncio to use high precision clock, not about changing |
|
@gvanrossum: Trio also always uses time.perf_counter for high precision monotonic clock. |
|
@kumaraditya303 and @vstinner, unfortunately I don't have time to read #88494, but maybe you can? I'd like an approval from @vstinner if he thinks this is okay for asyncio before I merge this. |
I don't have time to read the entire #88494, but one thing which stood out from issue is that #85471 was resolved by switching to perf counter on Windows. @vstinner would know more since he worked on the code. |
|
I have some worries about using QueryPerformanceCounter() as time.monotonic() on Windows. So far, I'm not convinced that it's safe. The details are in #88494. This issue has a long history and is complicated because it's a complicated problem, and Windows doesn't provide any clock which fits all requirements. Moreover, there are also questions about how clocks behave on Windows 7 and Windows 8, and if Python 3.12 still support these operating systems. I don't have the bandwidth to dig into this complicated issue. So I cannot review this asyncio change. |
All things aside, CPython 3.9+ does not support Windows 7 so it is irrelevant. |
|
@zooba Do you have any opinion on this? |
No, sorry. If you need one from me, I'll have to schedule some research time next week to figure out what my opinion would be. |
Take your time, there is no rush for this. Thank you! |
|
Had a long chat with Steve Dower about this. We found that there's one outright bug in the PR, it doesn't change how It looks that since at least Windows 7, perf_counter() is monotonic, so no worries about that. But there's a possibility that If it does, maybe it's actually correct, on Windows, to use the resolution of the monotonic clock, but only coincidentally. I think @zooba will add more color. |
|
I had a look at this with Guido and have the following suggestions:
The only weirdness is using the If someone uses |
Okay, closing. Thanks for the info. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
