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 — bpo-21302: Add clock_nanosleep() implementation for time.sleep() by Livius90 · Pull Request #28111 · python/cpython

Conversation

@Livius90

@Livius90 Livius90 commented Sep 1, 2021 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor
  • Add clock_nanosleep() function to time.sleep() in Unix operation systems.

Requested changes from @vstinner are done. It was runt-time tested in Oracle Linux 8.4 and Windows 10.
Some previous pull request history can be found here: #28077

https://bugs.python.org/issue21302

Sorry, something went wrong.

Uh oh!

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

evanfoster and Livius90 reacted with hooray emoji
All reactions
  • 🎉 2 reactions
@Livius90
clock_nanosleep() implementation for time.sleep()
55faeb6
clock_nanosleep() is available in Linux which has POSIX 2001.12 or newer
@Livius90
Livius90 requested review from abalkin and pganssle as code owners September 1, 2021 13:00
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Sep 1, 2021
@bedevere-bot bedevere-bot added the awaiting review label Sep 1, 2021
@Livius90 Livius90 mentioned this pull request Sep 1, 2021
[3.10] bpo-21302: Add clock_nanosleep() implementation for time.sleep() in Linux #28077
Closed
vstinner
vstinner reviewed Sep 1, 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.

Oh nice, it's much better!

IMO it's worth to mention that time.sleep() has a resolution of 1 nanosecond if the clock_nanosleep() function is available.

Do you know if clock_nanosleep() is available on other platforms than Linux? Is it available on macOS or FreeBSD for example?

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread configure.ac Resolved

Uh oh!

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

Comment thread Modules/timemodule.c Resolved

Uh oh!

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

@Livius90

Livius90 commented Sep 1, 2021 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Oh nice, it's much better!

IMO it's worth to mention that time.sleep() has a resolution of 1 nanosecond if the clock_nanosleep() function is available.

Do you know if clock_nanosleep() is available on other platforms than Linux? Is it available on macOS or FreeBSD for example?

I do not think that it is available in macOS and FreeBSD according the gnulib manual, clock_nanosleep() is available sure in Linux from POSIX version 2001.12. So any modern and new Linux based OS has it, moreover it seems to me QNX has also the same clock_nanosleep().

Is there any right place to mention this improved resolution of time.sleep()?

All reactions

Sorry, something went wrong.

Uh oh!

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

Livius90 added 4 commits September 1, 2021 16:35
@Livius90
Follow PEP 7 rules in time.sleep()
c7bae3b
PEP 7 rules appled for _PyTime_AsTimespec and _PyTime_AsTimeval error checking in pysleep().
@Livius90
Adjust braces to PEP 7
b3a5c5f
@Livius90
clock_nanosleep check placed after clock_settime
3e07f39
@Livius90
Fix EINTR issue for clock_nanosleep()
e06ba84
In calling clock_nanosleep() EINTR is not stored in errno. Need to use return value of clock_nanosleep()/select() for checking it.
@Livius90
Livius90 requested a review from vstinner September 1, 2021 16:58
blurb-it Bot and others added 3 commits September 1, 2021 17:12
@blurb-it
📜🤖 Added by blurb_it.
6e6d4a3
@Livius90
nanosleep() is available for Unix systems like OSX, FreeBSD
238f073
@Livius90
Update news rst file
b5a5c6e
Unix operating systems eg: Linux, macOS, FreeBSD etc. time.sleep() has a resolution of nanoseconds with using clock_nanosleep() or nanosleep() function.
@Livius90

Livius90 commented Sep 1, 2021 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

In all Unix systems eg: macOS, FreeBSD, Linux etc, nanosleep() is available and as i see there are some codes where select() is used for sleeping microsecs resolution, semaphore.c, _tkinter.c. Sleeping via select() was the state of the art solution in about 1998 in Linux but it is already an outdated solution nowadays. It would be better to use nanosleep() in these codes also.

I will improve it in the rest of codes, too.

All reactions

Sorry, something went wrong.

Uh oh!

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

Livius90 and others added 2 commits September 2, 2021 22:22
@Livius90
replace select() with nanosleep()
d064255
In all Unix systems eg: macOS, FreeBSD, Linux etc, nanosleep() is available.
@blurb-it
📜🤖 Added by blurb_it.
b70f187
@Livius90 Livius90 changed the title bpo-21302: Add clock_nanosleep() implementation for time.sleep() in Linux bpo-21302: Add clock_nanosleep() and nanosleep() implementation for time.sleep() in Unix systems Sep 2, 2021
Livius90 and others added 4 commits September 2, 2021 23:37
@Livius90
Fix test_eintr issue for macOS
6ad7c14
@Livius90
Remove news rst and regenerate
74c45e1
@blurb-it
📜🤖 Added by blurb_it.
5988222
@Livius90
Use waitable timer from Win32 for time.sleep() in Windows
129b0a0
Waitable timer is 100 nsec resolution. Now, seconds to nanosec conversion is limited in usec, soon will come the next developing part to improve it in next commit.
@Livius90 Livius90 changed the title bpo-21302: Add clock_nanosleep() and nanosleep() implementation for time.sleep() in Unix systems bpo-21302: Add clock_nanosleep(), nanosleep() and waitable timer implementation for time.sleep() Sep 3, 2021
Livius90 and others added 4 commits September 3, 2021 23:25
@Livius90
Finalized waitable timer for time.sleep() in Windows
d89e13b
Waitable timer resolution is 100 nsec but it is limited to 1 usec by round ceiling, moreover sleep for lower then 1 milisec is not possible in Win32 API.
@blurb-it
📜🤖 Added by blurb_it.
47249f5
@Livius90
Fix macOS build issue
0bf8330
@blurb-it
📜🤖 Added by blurb_it.
085cbed
@Livius90

Livius90 commented Sep 3, 2021 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Improved time.sleep() is ready for final review. All platforms have now the state of the art solution for sleeping. In Windows it uses Waitable timer object, in Linux it is clock_nanosleep() and in other Unix systems eg: macOS, FreeBSD it is nanosleep() function.

Resolution of Waitable timer object is 100 nsec but it is limited to 1 usec by round ceiling. However, sleeping for lower than 1 millisec is not possible in Win32 API because the overhead of the the event waiting call is more than nanoseconds.

Resolution of clock_nanosleep() and nanosleep() is 1 nsec, clock_nanosleep() is suitable for blocking/waiting until an absolute time date, nanosleep() is suitable only for interval sleeping.

@abalkin, @pganssle and @vstinner please make a review for my final state.

All reactions

Sorry, something went wrong.

Uh oh!

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

@Livius90
Simplified HAVE_CLOCK_NANOSLEEP macro blocks
92061f3
@Livius90
Livius90 requested a review from vstinner September 10, 2021 19:52
Livius90 and others added 18 commits September 10, 2021 23:00
@Livius90
remake news
f045047
@blurb-it
📜🤖 Added by blurb_it.
24f9975
@Livius90
Fix err checking
34e3883
@blurb-it
📜🤖 Added by blurb_it.
fec634f
@Livius90
revert changes
8022062
Can not simplify HAVE_CLOCK_NANOSLEEP blocks because do {} while loop need for EINTR error handling
@Livius90
get_monotonic() and secs re-calculation are useless for clock_nanosle…
4685ec7
…ep()
@blurb-it
📜🤖 Added by blurb_it.
0ad19e0
@Livius90
merge errno in HAVE_CLOCK_NANOSLEEP
0839d0d
@Livius90
remake news rst
39cff8f
@blurb-it
📜🤖 Added by blurb_it.
87d5712
@Livius90
Try to fix Address sanitizer test issue
56cb8e1
@blurb-it
📜🤖 Added by blurb_it.
8ec03be
@Livius90
#2 Try to fix Address sanitizer test issue
b1ccdba
@blurb-it
📜🤖 Added by blurb_it.
c8372c8
@Livius90
remake news rst
1cf2205
@blurb-it
📜🤖 Added by blurb_it.
1e725da
@Livius90
re-make news rst
3566c59
@blurb-it
📜🤖 Added by blurb_it.
278aaa2
@vstinner
vstinner merged commit 85a4748 into python:main Sep 13, 2021
@bedevere-bot bedevere-bot removed the awaiting review label Sep 13, 2021
@vstinner

vstinner commented Sep 13, 2021

Copy link
Copy Markdown
Member

Merged, thanks! I created PR #28311 follow-up to update the documentation.

All reactions

Sorry, something went wrong.

Uh oh!

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

@Livius90

Livius90 commented Sep 13, 2021 •
edited by bedevere-bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Thanks the merging.

What are the formal rules to create a new PR to improve Windows implementation, too? Is it good to create a new PR without any bpo issue number? Or can i make more PR (windows implementation and nanosleep()) for this bpo-21302?

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Sep 13, 2021 •
edited by bedevere-bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

In this case, you can reuse bpo-21302.

All reactions

Sorry, something went wrong.

Uh oh!

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

@Livius90 Livius90 mentioned this pull request Sep 14, 2021
bpo-21302: Add Waitable timer implementation for time.sleep() in Windows #28341
Closed
@Livius90 Livius90 mentioned this pull request Sep 22, 2021
bpo-21302: Add nanosleep() implementation for time.sleep() in Unix #28526
Closed
@shankarunni shankarunni mannequin mentioned this pull request Nov 12, 2022
time.sleep (floatsleep()) should use clock_nanosleep() on Linux #65501
Closed
@haukex haukex mentioned this pull request Feb 4, 2023
Allow sleeping until an absolute time #101558
Open
@hauntsaninja hauntsaninja mentioned this pull request Dec 28, 2024
gh-125997: ensure that time.sleep(0) is not delayed on non-Windows platforms #128274
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

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

Uh oh!

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

Assignees

No one assigned

Labels

None yet

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 @vstinner @the-knights-who-say-ni @bedevere-bot
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.