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

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

Merged
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

@vstinner vstinner commented Sep 20, 2021

@vstinner
Copy link
Member Author

@vstinner vstinner commented Sep 20, 2021

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

@vstinner vstinner commented Sep 21, 2021

@vstinner vstinner merged commit 58f8adf into python:main Sep 22, 2021
12 checks passed
@vstinner vstinner deleted the win_sleep branch Sep 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants