8000 bpo-21302: time.sleep() uses waitable timer on Windows by vstinner · Pull Request #28483 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
8000

bpo-21302: time.sleep() uses waitable timer on Windows #28483

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

Merged
merged 1 commit into from
Sep 22, 2021
Merged

bpo-21302: time.sleep() uses waitable timer on Windows #28483

merged 1 commit into from
Sep 22, 2021

Conversation

vstinner
Copy link
Member
@vstinner vstinner commented Sep 20, 2021

On Windows, time.sleep() now uses a waitable timer which has a
resolution of 100 ns (10^-7 sec). Previously, it had a solution of 1
ms (10^-3 sec).

  • On Windows, time.sleep() now calls PyErr_CheckSignals() before
    resetting the SIGINT event.
  • Add _PyTime_As100Nanoseconds() function.
  • Complete and update time.sleep() documentation.

Co-Authored-by: Livius egyszeregy@freemail.hu

https://bugs.python.org/issue21302

On Windows, time.sleep() now uses a waitable timer which has a
resolution of 100 ns (10^-7 sec). Previously, it had a solution of 1
ms (10^-3 sec).

* On Windows, time.sleep() now calls PyErr_CheckSignals() before
  resetting the SIGINT event.
* Add _PyTime_As100Nanoseconds() function.
* Complete and update time.sleep() documentation.

Co-Authored-by: Livius <egyszeregy@freemail.hu>
@vstinner
Copy link
Member Author

cc @Livius90

@vstinner
Copy link
Member Author

Manual test using wait.py attached to the issue:

vstinner@DESKTOP-DK7VBIL C:\vstinner\python\main>python wait.py
sleep 5 seconds... press CTRL+C to interrupt it
dt: 4986340400 ns (4.986 sec)

vstinner@DESKTOP-DK7VBIL C:\vstinner\python\main>python wait.py
Running Debug|x64 interpreter...
sleep 5 seconds... press CTRL+C to interrupt it
[0.6] got SIGINT!
[1.6] got SIGINT!
[1.7] got SIGINT!
[1.9] got SIGINT!
[3.1] got SIGINT!
[4.0] got SIGINT!
dt: 4992658600 ns (4.993 sec)

It's not exactly 5.000 sec because wait.py uses time.perf_counter_ns(). If you change it to use time.monotonic_ns(), it is closer to 5.0 sec ;-)

@vstinner
Copy link
Member Author

cc @corona10 @pablogsal

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

Successfully merging this pull request may close these issues.

3 participants
0