-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
[3.10] bpo-21302: Add clock_nanosleep() implementation for time.sleep() in Linux #28077
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
Conversation
clock_nanosleep() is available in Linux which has POSIX 2001.12 or newer.
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). Recognized GitHub usernameWe couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames: This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 3.10 branch no longer accept new features. I consider this PR as a new feature: please retarget this PR to the main branch. I suggest to create a new PR, it's simpler. Please CC-me there (@vstinner).
@@ -60,6 +60,10 @@ | |||
# define HAVE_CLOCK_GETTIME_RUNTIME 1 | |||
#endif | |||
|
|||
#if (!defined(MS_WINDOWS) && defined(__linux__) && defined(_POSIX_VERSION)) && (_POSIX_VERSION >= 200112L) | |||
# define HAVE_CLOCK_NANOSLEEP 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer a check in configure.
#ifdef HAVE_CLOCK_NANOSLEEP | ||
struct timespec request; | ||
request.tv_sec = timeout.tv_sec; | ||
request.tv_nsec = (long)(timeout.tv_usec) * 1000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line makes me sad. The caller uses nanosecond resolution (10^-9), then _PyTime_AsTimeval() truncates to microsecond resolution (10^-6).
I would prefer to inline this code in pysleep() and avoid _PyTime_AsTimeval() for the clock_nanosleep() code path.
struct timespec request; | ||
request.tv_sec = timeout.tv_sec; | ||
request.tv_nsec = (long)(timeout.tv_usec) * 1000; | ||
ret = clock_nanosleep(CLOCK_MONOTONIC, 0, &request, NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to avoid computing the relative 'timeout' value, but just pass 'deadline' absolute time since it's already computed: use flags=TIMER_ABSTIME.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
https://bugs.python.org/issue21302
Add clock_nanosleep() as a feature fix in Linux operation systems which have 2001.12 or newer version of POSIX.
https://bugs.python.org/issue21302