Skip to content
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

bpo-21302: Add nanosleep() implementation for time.sleep() in Unix #28526

Closed
wants to merge 5 commits into from
Closed

bpo-21302: Add nanosleep() implementation for time.sleep() in Unix #28526

wants to merge 5 commits into from

Conversation

Livius90
Copy link
Contributor

@Livius90 Livius90 commented Sep 22, 2021

  • 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

https://bugs.python.org/issue21302

Replace outdated select() to use nanosleep() for sleep implementation in Unix
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.

I would prefer to restrict this PR to using nanosleep() in time.sleep(), and nothing else. IMO it's already complex enough :-)

Modules/_tkinter.c Outdated Show resolved Hide resolved
Modules/_multiprocessing/semaphore.c Outdated Show resolved Hide resolved
Modules/timemodule.c Show resolved Hide resolved
@@ -2074,7 +2076,11 @@ pysleep(_PyTime_t secs)
#endif

do {
#ifndef HAVE_CLOCK_NANOSLEEP
#if defined(HAVE_NANOSLEEP) && !defined(HAVE_CLOCK_NANOSLEEP)
Copy link
Member

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?

@vstinner
Copy link
Member

I merged PR #28545.

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