[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux

STINNER Victor report at bugs.python.org
Sun Apr 27 01:59:46 CEST 2014


STINNER Victor added the comment:

If you want to modify time.sleep(), you must be careful of the portability: Windows, Linux, but also Mac OS X, FreeBSD, Solaris, etc.

Try to describe the behaviour of each underlying C function on each platform to be able to describe the "portable behaviour" on all platforms, especially the expected behaviour when the system clock is changed (is time.sleep impacted or not? always?) and the expected behaviour when the system is suspended.

For example, it looks like nanosleep() uses a different clock depending on OS (Linux uses CLOCK_MONOTONIC, other UNIX platforms use CLOCK_REALTIME).
http://lists.gnu.org/archive/html/bug-coreutils/2012-08/msg00087.html

I know that you suggest to use clock_nanosleep(), but this function is not available on all platforms. For example, I would not use it on Windows.

Another example (on Fedora?): "sleep() ignores time spent with a suspended system"
http://mjg59.dreamwidth.org/7846.html

You should also decide how to handle interrupted sleep (C error "EINTR"). Currently, the sleep is interrupted, no error is raised.

I began to describe all these functions in the PEP 418, even if I didn't change the implementation with the PEP:
http://legacy.python.org/dev/peps/pep-0418/#sleep

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21302>
_______________________________________


More information about the Python-bugs-list mailing list