bpo-21302: Add nanosleep() implementation for time.sleep() in Unix by Livius90 · Pull Request #28526 · python/cpython
- Use nanosleep() for time.sleep() in Unix operation systems in case if clock_nanosleep() is not available but nanosleep() is available.
Some previous pull request history can be found here: #28111, #28341, #28483
- nanosleep() is supported in the following operating systems: Linux (since 2001), FreeBSD (since 1997), OpenBSD (since 1997), NetBSD (since 1997), IBM AIX (since v7.1 2010), macOS (since OS X v10.9 2013)
- clock_nanosleep() is supported in the following operating systems: Linux (since 2001), FreeBSD (since 2008), NetBSD (since 2014), IBM AIX (since v7.1 2010)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to restrict this PR to using nanosleep() in time.sleep(), and nothing else. IMO it's already complex enough :-)
|
|
||
| do { | ||
| #ifndef HAVE_CLOCK_NANOSLEEP | ||
| #if defined(HAVE_NANOSLEEP) && !defined(HAVE_CLOCK_NANOSLEEP) |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change LGTM, but I propose to write the #ifdef dance differently and rename secs to timeout to make the code more readable. I created PR #28545 based on your PR. Is it better? For the main code in Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS, I merged the 3 code paths to put if #ifdef in the Py_BEGIN_ALLOW_THREADS block. What do you think?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters