bpo-21302: Add clock_nanosleep() implementation for time.sleep() by Livius90 · Pull Request #28111 · python/cpython

@Livius90

clock_nanosleep() is available in Linux which has POSIX 2001.12 or newer

vstinner

PEP 7 rules appled for _PyTime_AsTimespec and _PyTime_AsTimeval error checking in pysleep().

@Livius90

@Livius90

In calling clock_nanosleep() EINTR is not stored in errno. Need to use return value of clock_nanosleep()/select() for checking it.

@blurb-it

@Livius90

Unix operating systems eg: Linux, macOS, FreeBSD etc. time.sleep() has a resolution of nanoseconds with using clock_nanosleep() or nanosleep() function.
In all Unix systems eg: macOS, FreeBSD, Linux etc, nanosleep() is available.

@blurb-it

@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

@Livius90

@blurb-it

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

@Livius90

@blurb-it

@Livius90

@Livius90

@blurb-it

@Livius90

@blurb-it

Can not simplify HAVE_CLOCK_NANOSLEEP blocks because do {} while loop need for EINTR error handling

@Livius90

@blurb-it

@Livius90

@Livius90

@blurb-it

@Livius90

@blurb-it

@Livius90

@blurb-it

@Livius90

@blurb-it

@Livius90

@blurb-it