8000 [3.10] bpo-21302: Add clock_nanosleep() implementation for time.sleep() in Linux by Livius90 · Pull Request #28077 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[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

Closed
wants to merge 1 commit into from
Closed

Conversation

Livius90
Copy link
Contributor
@Livius90 Livius90 commented Aug 30, 2021

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

clock_nanosleep() is available in Linux which has POSIX 2001.12 or newer.
@the-knights-who-say-ni
Copy link

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 username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@Livius90

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!

Copy link
Member
@vstinner vstinner left a 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
Copy link
Member

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;
Copy link
Member

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);
Copy link
Member

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.

@bedevere-bot
Copy link

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@Livius90
Copy link
Contributor Author
Livius90 commented Sep 1, 2021

Requested changes from @vstinner are done.
#28111

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0