GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [3.10] bpo-21302: Add clock_nanosleep() implementation for time.sleep() in Linux by Livius90 · Pull Request #28077 · python/cpython

Conversation

@Livius90

@Livius90 Livius90 commented Aug 30, 2021 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Livius90
clock_nanosleep() implementation for time.sleep()
017efd1
clock_nanosleep() is available in Linux which has POSIX 2001.12 or newer.
@Livius90
Livius90 requested review from abalkin and pganssle as code owners August 30, 2021 22:49
@the-knights-who-say-ni

the-knights-who-say-ni commented Aug 30, 2021

Copy link
Copy Markdown

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!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@the-knights-who-say-ni the-knights-who-say-ni added the CLA not signed label Aug 30, 2021
@bedevere-bot bedevere-bot added the awaiting review label Aug 30, 2021
vstinner
vstinner requested changes Aug 31, 2021
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

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).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Modules/timemodule.c
#endif

#if (!defined(MS_WINDOWS) && defined(__linux__) && defined(_POSIX_VERSION)) && (_POSIX_VERSION >= 200112L)
# define HAVE_CLOCK_NANOSLEEP 1

@vstinner vstinner Aug 31, 2021

Copy link
Copy Markdown
Member

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Modules/timemodule.c
#ifdef HAVE_CLOCK_NANOSLEEP
struct timespec request;
request.tv_sec = timeout.tv_sec;
request.tv_nsec = (long)(timeout.tv_usec) * 1000;

@vstinner vstinner Aug 31, 2021

Copy link
Copy Markdown
Member

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Modules/timemodule.c
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);

@vstinner vstinner Aug 31, 2021

Copy link
Copy Markdown
Member

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting changes and removed awaiting review labels Aug 31, 2021
@bedevere-bot

bedevere-bot commented Aug 31, 2021

Copy link
Copy Markdown

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@the-knights-who-say-ni the-knights-who-say-ni added CLA signed and removed CLA not signed labels Aug 31, 2021
@Livius90 Livius90 closed this Sep 1, 2021
@Livius90
Livius90 deleted the bpo-21302 branch September 1, 2021 09:33
@Livius90 Livius90 mentioned this pull request Sep 1, 2021
bpo-21302: Add clock_nanosleep() implementation for time.sleep() #28111
Merged
@Livius90

Livius90 commented Sep 1, 2021

Copy link
Copy Markdown
Contributor Author

Requested changes from @vstinner are done.
#28111

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@shankarunni shankarunni mannequin mentioned this pull request Nov 12, 2022
time.sleep (floatsleep()) should use clock_nanosleep() on Linux #65501
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner requested changes
@abalkin abalkin Awaiting requested review from abalkin abalkin is a code owner
@pganssle pganssle Awaiting requested review from pganssle pganssle is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting changes

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@Livius90 @the-knights-who-say-ni @bedevere-bot @vstinner
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.