diff options
author | Victor Stinner <vstinner@python.org> | 2021-09-22 14:09:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-22 14:09:30 (GMT) |
commit | 58f8adfda3c2b42f654a55500e8e3a6433cb95f2 (patch) | |
tree | 2804e1290e728fe7f5aa6ba46215b894de3f88ea /Doc/library/time.rst | |
parent | 8620be99da930230b18ec05f4d7446ee403531af (diff) | |
download | cpython-58f8adfda3c2b42f654a55500e8e3a6433cb95f2.zip cpython-58f8adfda3c2b42f654a55500e8e3a6433cb95f2.tar.gz cpython-58f8adfda3c2b42f654a55500e8e3a6433cb95f2.tar.bz2 |
bpo-21302: time.sleep() uses waitable timer on Windows (GH-28483)
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>
Diffstat (limited to 'Doc/library/time.rst')
-rw-r--r-- | Doc/library/time.rst | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/Doc/library/time.rst b/Doc/library/time.rst index 34cb28f..d91862c 100644 --- a/Doc/library/time.rst +++ b/Doc/library/time.rst @@ -351,22 +351,35 @@ Functions Suspend execution of the calling thread for the given number of seconds. The argument may be a floating point number to indicate a more precise sleep - time. The actual suspension time may be less than that requested because any - caught signal will terminate the :func:`sleep` following execution of that - signal's catching routine. Also, the suspension time may be longer than - requested by an arbitrary amount because of the scheduling of other activity - in the system. + time. + + If the sleep is interrupted by a signal and no exception is raised by the + signal handler, the sleep is restarted with a recomputed timeout. + + The suspension time may be longer than requested by an arbitrary amount, + because of the scheduling of other activity in the system. + + On Windows, if *secs* is zero, the thread relinquishes the remainder of its + time slice to any other thread that is ready to run. If there are no other + threads ready to run, the function returns immediately, and the thread + continues execution. + + Implementation: + + * On Unix, ``clock_nanosleep()`` is used if available (resolution: 1 ns), + or ``select()`` is used otherwise (resolution: 1 us). + * On Windows, a waitable timer is used (resolution: 100 ns). If *secs* is + zero, ``Sleep(0)`` is used. + + .. versionchanged:: 3.11 + On Unix, the ``clock_nanosleep()`` function is now used if available. + On Windows, a waitable timer is now used. .. versionchanged:: 3.5 The function now sleeps at least *secs* even if the sleep is interrupted by a signal, except if the signal handler raises an exception (see :pep:`475` for the rationale). - .. versionchanged:: 3.11 - In Unix operating systems, the ``clock_nanosleep()`` function is now - used, if available: it allows to sleep for an interval specified with - nanosecond precision. - .. index:: single: % (percent); datetime format |