New submission from Shankar Unni:

I know that an earlier request to use nanosleep() has been rejected as 
"wontfix", but I'm filing this one for a different reason.

Today, timemodule.c:floatsleep() calls select() on platforms that support it. 
On Linux, select() with a timeout has an unfortunate property that it is very 
sensitive to clock jumps, because it computes a sleep end time based on the 
current kernel timestamp.

If the system clock is yanked back (by ntpd, or other processes), then the 
process can end up sleeping for a very long time. (E.g. if the clock is yanked 
back by half an hour while we are in the middle of, say, a sleep(10), then the 
process will sleep until "original_kernel_clock+10", which will turn into a 
half-hour sleep.

Yes, systems shouldn't jerk their clocks around, but we can't often control 
this sort of thing on end-user environments.

Using clock_nanosleep(CLOCK_MONOTONIC, 0, <timespec>, NULL) makes the sleep a 
much more reliable thing, and mostly insensitive to such jumps. (It'll still be 
affected by any adjtime(), but that's OK in this case).

----------
components: Library (Lib)
messages: 216799
nosy: shankarunni
priority: normal
severity: normal
status: open
title: time.sleep (floatsleep()) should use clock_nanosleep() on Linux
type: behavior

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to