bpo-21302: Add nanosleep() implementation for time.sleep() in Unix by Livius90 · Pull Request #28526 · python/cpython

@Livius90

  • 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

@Livius90

Replace outdated select() to use nanosleep() for sleep implementation in Unix

@blurb-it

vstinner

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

vstinner


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

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