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
bpo-45429: Support CREATE_WAITABLE_TIMER_HIGH_RESOLUTION if possible #29203
Conversation
Co-authored-by: Eryk Sun <eryksun@gmail.com>
aa8d2ef
to
eabd853
@vstinner gentle ping |
Modules/timemodule.c
Outdated
@@ -2017,6 +2024,23 @@ time_exec(PyObject *module) | |||
utc_string = tm.tm_zone; | |||
#endif | |||
|
|||
#if defined(MS_WINDOWS) | |||
if ((LONG)timer_flags == -1) { |
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.
if ((LONG)timer_flags == -1) { | |
if (timer_flags == (DWORD)-1) { |
Modules/timemodule.c
Outdated
#define CREATE_WAITABLE_TIMER_HIGH_RESOLUTION 0x00000002 | ||
#endif | ||
|
||
static DWORD timer_flags = -1; |
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.
static DWORD timer_flags = -1; | |
static DWORD timer_flags = (DWORD)-1; |
@@ -0,0 +1,3 @@ | |||
On Windows, :func:`time.sleep` now uses a waitable timer which supports | |||
high-resolution timers without increasing the timer frequency if possible. |
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 suggest to omit "without increasing the timer frequency if possible":
high-resolution timers without increasing the timer frequency if possible. | |
high-resolution timers. |
(same change where you copied this doc)
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.
Maybe you can explain that in Python 3.10, the best resolution was 1 ms, whereas it's now better (smaller) than 1 ms.
The change works as expected on my Windows 10 "version 21H1" VM ("OS Build 19043.1348"). On a debug build (worse performance than a release build), bench.py of https://bugs.python.org/issue21302 says:
With this PR, I get:
It's ~1000x more accurate: ms (10^-3 sec) => us (10^-6 sec)! |
@@ -272,6 +272,10 @@ time | |||
a resolution of 1 millisecond (10\ :sup:`-3` seconds). | |||
(Contributed by Benjamin Szőke and Victor Stinner in :issue:`21302`.) | |||
|
|||
* On Windows, :func:`time.sleep` now uses a waitable timer which supports high-resolution timers. | |||
In Python 3.10, the best resolution was 1 ms, from Python 3.11 it's now smaller than 1 ms. |
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.
Maybe try to merge this this item with the previous one.
LGTM. The code is correct, there is maybe a way to enhance the What's New In Python 3.11 doc.
Will do it at separated PR (maybe tomorrow) |
https://bugs.python.org/issue45429
The text was updated successfully, but these errors were encountered: