Skip to content

Commit 40d56f1

Browse files
committed
address Victor's review
1 parent ff06516 commit 40d56f1

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Doc/whatsnew/3.14.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,9 @@ Two new events are added: :monitoring-event:`BRANCH_LEFT` and
621621
time
622622
----
623623

624-
* Ensure that :func:`time.sleep(0) <time.sleep>` does not degrade over time
625-
on non-Windows platforms.
624+
* Ensure that the duration of :func:`time.sleep(0) <time.sleep>` is as small
625+
as possible on non-Windows platforms when :manpage:`clock_nanosleep(2)`
626+
or :manpage:`nanosleep(2)` are used to implement :func:`!time.sleep`.
626627
(Contributed by Bénédikt Tran in :gh:`125997`.)
627628

628629

Modules/timemodule.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,8 +2222,7 @@ pysleep(PyTime_t timeout)
22222222
#else
22232223
PyTime_t timeout_100ns = _PyTime_As100Nanoseconds(timeout,
22242224
_PyTime_ROUND_CEILING);
2225-
// Maintain Windows Sleep() semantics for time.sleep(0)
2226-
if (timeout_100ns == 0) {
2225+
if (timeout_100ns == 0) { // gh-125997
22272226
return pysleep_zero();
22282227
}
22292228
#endif
@@ -2397,9 +2396,9 @@ pysleep(PyTime_t timeout)
23972396
//
23982397
// Rationale
23992398
// ---------
2400-
// time.sleep(0) accumulates delays in the generic implementation, but we can
2401-
// skip some calls to `PyTime_Monotonic()` and other checks when the timeout
2402-
// is zero. For details, see https://github.com/python/cpython/pull/128274.
2399+
// time.sleep(0) is slower when using the generic implementation, but we make
2400+
// it faster than time.sleep(eps) for eps > 0 so to avoid some performance
2401+
// annoyance. For details, see https://github.com/python/cpython/pull/128274.
24032402
static int
24042403
pysleep_zero(void)
24052404
{
@@ -2442,7 +2441,7 @@ pysleep_zero(void)
24422441
if (PyErr_CheckSignals()) {
24432442
return -1;
24442443
}
2445-
#else
2444+
#else // Windows implementation
24462445
Py_BEGIN_ALLOW_THREADS
24472446
// A value of zero causes the thread to relinquish the remainder of its
24482447
// time slice to any other thread that is ready to run. If there are no

0 commit comments

Comments
 (0)