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

2021-10-11 Thread STINNER Victor


STINNER Victor  added the comment:

This issue is closed. If you consider that time.sleep() has a bug or could be 
enhanced, please open a new issue.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-10-11 Thread STINNER Victor


STINNER Victor  added the comment:

> That said, using a waitable timer leaves the door open for improvement in 
> future versions of Python. In particular, it's possible to get higher 
> resolution in newer versions of Windows 10 and Windows 11 with 
> CreateWaitableTimerExW() and the undocumented flag 
> CREATE_WAITABLE_TIMER_HIGH_RESOLUTION (2).

I created bpo-45429 "[Windows] time.sleep() should use 
CREATE_WAITABLE_TIMER_HIGH_RESOLUTION".

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-10-10 Thread Eryk Sun


Eryk Sun  added the comment:

> Absolute timeout using can reduce the overhead time of any variable 
> and object intialization cost before the WaitForMultipleObjects() 

Again, timer objects store the due time in interrupt time, not system time 
(i.e. InterruptTime vs SystemTime in the KUSER_SHARED_DATA record). The due 
time gets set as the current interrupt time plus a relative due time. If the 
due time is passed as absolute system time, the kernel just computes the delta 
from the current system time.

The timer object does record whether the requested due time is an absolute 
system time. This allows the kernel to recompute all absolute due times when 
the system time is changed manually. This is also the primary reason one 
wouldn't implement time.sleep() with absolute system time.

> using absolute timeout and GetSystemTimePreciseAsFileTime() can 
> improves the accuracy of the desired sleep time.

It would not improve the resolution. Timer objects are signaled when their due 
time is at or before the current interrupt time. The latter gets updated by the 
timer interrupt service routine, by default every 15.625 ms -- or at least that 
used to be the case.

The undocumented flag CREATE_WAITABLE_TIMER_HIGH_RESOLUTION creates a different 
timer type, called an "IRTimer" (implemented in Windows 8.1, but back then only 
accessible in the NT API). This timer type is based on precise interrupt time, 
which is interpolated using the performance counter. I don't know how the 
implementation of the timer interrupt has changed to support this increased 
resolution. It could be that the default 15.625 ms interrupt period is being 
simulated for compatibility with classic timers and Sleep(). I'd love for the 
CREATE_WAITABLE_TIMER_HIGH_RESOLUTION flag and the behavior of IRTimer objects 
to be documented.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-10-10 Thread Benjamin Szőke

Benjamin Szőke  added the comment:

In other words, using absolute timeout can eliminate the systematic error of 
desired sleep time.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-10-10 Thread Benjamin Szőke

Benjamin Szőke  added the comment:

It is not true that there are no benefits. Absolute timeout using can reduce 
the overhead time of any variable and object intialization cost before the 
WaitForMultipleObjects() which will perform the real sleeping via blocking wait 
in pysleep(). GetSystemTimePreciseAsFileTime() must be call at the first line 
as much as it can in pysleep(). This is the same implementation in Linux via 
clock_nanosleep().

So, to using absolute timeout and GetSystemTimePreciseAsFileTime() can improves 
the accuracy of the desired sleep time. For example if sleep = 2.0 sec then 
real relative sleep time = 2.001234 sec, but absolute sleep time = 2.12 sec.

Benefits are in not the technicaly backgorund, rather it is in the usecase.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-10-09 Thread Eryk Sun


Eryk Sun  added the comment:

> Is there any benefit of calling SetWaitableTimer() with an 
> absolute timeout

No, the due time of a timer object is stored in absolute interrupt time, not 
absolute system time. This has to be calculated either way, and it's actually 
more work for the kernel if an absolute system time is passed.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-10-09 Thread Benjamin Szőke

Benjamin Szőke  added the comment:

Absolute timeout implementation via SetWaitableTimer() and 
GetSystemTimePreciseAsFileTime() is always better because it can reduce the 
"waste time" or "overhead time" what is always exist in any simple interval 
sleep implementation. Moreover, it is the only one which is eqvivalent with 
clock_nanosleep() implementation of Linux which is now the most state of the 
art implementation for precise sleeping.

So, my opinion is that absolute timeout implementation could be the most modern 
and sustainable for future python.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-10-09 Thread Eryk Sun


Eryk Sun  added the comment:

> In Python 3.11, time.sleep() is now always implemented with a 
> waitable timer. 

A regular waitable timer in Windows becomes signaled with the same resolution 
as Sleep(). It's based on the current interrupt timer period, which can be 
lowered to 1 ms via timeBeginPeriod(). Compared to Sleep() it's more flexible 
in terms of periodic waits, WaitForMultipleObjects(), or 
MsgWaitForMultipleObjects() -- not that time.sleep() needs this flexibility.

That said, using a waitable timer leaves the door open for improvement in 
future versions of Python. In particular, it's possible to get higher 
resolution in newer versions of Windows 10 and Windows 11 with 
CreateWaitableTimerExW() and the undocumented flag 
CREATE_WAITABLE_TIMER_HIGH_RESOLUTION (2).

--
nosy: +eryksun

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-10-09 Thread STINNER Victor


STINNER Victor  added the comment:

> it is time to use nicely GetSystemTimePreciseAsFileTime() in time.time()

See bpo-19007 for that.

> it is time to (...) time.sleep() as absolute sleeping because it is available 
> since Windows 8.

In Python 3.11, time.sleep() is now always implemented with a waitable timer. I 
chose to use a relative timeout since it's simpler to implement. Is there any 
benefit of calling SetWaitableTimer() with an absolute timeout, compared to 
calling it with a relative timeout?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-10-09 Thread Benjamin Szőke

Benjamin Szőke  added the comment:

https://www.python.org/downloads/windows/
"Note that Python 3.10.0 cannot be used on Windows 7 or earlier."

vstinner: Is it true that Windows 7 is not supported OS anymore? In this case 
we do not need to care about Windows 7 and earlier Windows OS compatibility and 
it is time to use nicely GetSystemTimePreciseAsFileTime() in time.time() and 
time.sleep() as absolute sleeping because it is available since Windows 8.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-09-25 Thread STINNER Victor


STINNER Victor  added the comment:

> Do you have any information about when will be it released in 3.11?

Here is a schedule of Python 3.11 releases:
https://www.python.org/dev/peps/pep-0664/

In the meanwhile, you can develop a C extension to get the feature.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-09-25 Thread Benjamin Szőke

Benjamin Szőke  added the comment:

Do you have any information about when will be it released in 3.11?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-09-25 Thread STINNER Victor


STINNER Victor  added the comment:

Thanks Livius for all these nice enhancements!

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-09-25 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 7834ff26cbcd4d8394d64d80d9f51a364d38b1c6 by Victor Stinner in 
branch 'main':
bpo-21302: Add nanosleep() implementation for time.sleep() in Unix (GH-28545)
https://github.com/python/cpython/commit/7834ff26cbcd4d8394d64d80d9f51a364d38b1c6


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-09-24 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +26929
pull_request: https://github.com/python/cpython/pull/28545

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-09-22 Thread Benjamin Szőke

Change by Benjamin Szőke :


--
pull_requests: +26917
pull_request: https://github.com/python/cpython/pull/28526

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-09-22 Thread STINNER Victor


STINNER Victor  added the comment:

See also bpo-19007: "precise time.time() under Windows 8: use 
GetSystemTimePreciseAsFileTime".

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-09-22 Thread STINNER Victor


STINNER Victor  added the comment:

Livius: do you care about using nanosleep(), or can I close the issue?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-09-22 Thread STINNER Victor


STINNER Victor  added the comment:

> On Windows with a Python 3.11 debug build, I get:
> Mean +- std dev: 21.9 ms +- 7.8 ms (228 values)

I wrote an optimization to cache the Windows timer handle between time.sleep() 
calls (don't close it). I don't think that it's needed because they shortest 
sleep is about 15.6 ms. CreateWaitableTimerW() is likely way more fast than 
15.6 ms. So this optimization is basically useless.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-09-22 Thread STINNER Victor


STINNER Victor  added the comment:

bench.py: measure the shortest possible sleep. Use time.sleep(1e-10): 0.1 
nanosecond. It should be rounded to the resolution of the used sleep function, 
like 1 ns on Linux.

On Linux with Fedora 34 Python 3.10 executable, I get:

Mean +- std dev: 60.5 us +- 12.9 us (80783 values)

On Windows with a Python 3.11 debug build, I get:

Mean +- std dev: 21.9 ms +- 7.8 ms (228 values)

Sadly, it seems like on Windows 10, one of the following function still uses 
the infamous 15.6 ms resolution:

* CreateWaitableTimerW()
* SetWaitableTimer()
* WaitForMultipleObjects()

--
Added file: https://bugs.python.org/file50294/bench.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-09-22 Thread STINNER Victor


STINNER Victor  added the comment:

Livius: your first PR modified Sleep() in Modules/_tkinter.c to use 
nanosleep(). I don't see the point since this function has a solution of 1 ms 
(10^-3). Using select() on Unix is enough: resolution of 1 us (10^-6).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-09-22 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 58f8adfda3c2b42f654a55500e8e3a6433cb95f2 by Victor Stinner in 
branch 'main':
bpo-21302: time.sleep() uses waitable timer on Windows (GH-28483)
https://github.com/python/cpython/commit/58f8adfda3c2b42f654a55500e8e3a6433cb95f2


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-09-20 Thread STINNER Victor


STINNER Victor  added the comment:

wait.py: script to test the time.sleep() function. Press CTRL+C multiple times 
during the sleep to check that even if the sleep is interrupted, time.sleep() 
sleeps the expected duration.

--
Added file: https://bugs.python.org/file50289/wait.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-09-20 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +26882
pull_request: https://github.com/python/cpython/pull/28483

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-09-15 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset b49263b698993cad2b8aaddc55cdeaa678412b30 by Victor Stinner in 
branch 'main':
bpo-21302: Add _PyTime_AsNanoseconds() (GH-28350)
https://github.com/python/cpython/commit/b49263b698993cad2b8aaddc55cdeaa678412b30


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-09-15 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +26764
pull_request: https://github.com/python/cpython/pull/28350

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-09-14 Thread Benjamin Szőke

Change by Benjamin Szőke :


--
pull_requests: +26754
pull_request: https://github.com/python/cpython/pull/28341

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-09-13 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 85dc53a463967659075744ad911d08a32aa70dd5 by Victor Stinner in 
branch 'main':
bpo-21302: Update time.sleep() doc for clock_nanosleep() (GH-28311)
https://github.com/python/cpython/commit/85dc53a463967659075744ad911d08a32aa70dd5


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-09-13 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +26724
pull_request: https://github.com/python/cpython/pull/28311

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-09-13 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 85a4748118c3793be7047ecbcbfc79dd07cb2a75 by Livius in branch 
'main':
bpo-21302: Add clock_nanosleep() implementation for time.sleep() (GH-28111)
https://github.com/python/cpython/commit/85a4748118c3793be7047ecbcbfc79dd07cb2a75


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-09-05 Thread Benjamin Szőke

Benjamin Szőke  added the comment:

Can you review my final implementation?
https://github.com/python/cpython/pull/28111

--
versions: +Python 3.11

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-09-01 Thread Benjamin Szőke

Change by Benjamin Szőke :


--
nosy: +Livius
nosy_count: 5.0 -> 6.0
pull_requests: +26552
pull_request: https://github.com/python/cpython/pull/28111

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2021-08-30 Thread Roundup Robot


Change by Roundup Robot :


--
keywords: +patch
nosy: +python-dev
nosy_count: 4.0 -> 5.0
pull_requests: +26521
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/28077

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2014-04-26 Thread STINNER Victor

STINNER Victor added the comment:

 I know that an earlier request to use nanosleep() has been rejected as 
 wontfix

It was the issue #13981. I created this issue while I worked on the PEP 410 
(nanosecond timestamp). I closed the issue myself, it doesn't mean that Python 
must not use the function, just that I didn't want to work on it anymore at 
this time.

--

___
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



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

2014-04-26 Thread STINNER Victor

STINNER Victor added the comment:

I'm working on a patch, but I noticed a similar issue in Condition.wait(), 
which also keeps re-evaluating the remaining sleep time based on the current 
kernel clock, with similar effects.

I see that Lock.acquire(timeout) uses the C function gettimeofday() to 
recompute the timeout if acquiring the lock was interrupted (C error EINTR). 
It would be better to use a monotonic clock here, but please open a new issue 
because it's unrelated to nanosleep().

Or did you another bug?

By the way, you didn't mention the Python version. Are you working on Python 
2.7 or 3.5?

See also the PEP 418.

--

___
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



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

2014-04-26 Thread STINNER Victor

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



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

2014-04-26 Thread Shankar Unni

Shankar Unni 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.

Oh, I totally agree. What I'm trying to do is to define another autoconf flag 
(HAVE_CLOCK_NANOSLEEP), that does a feature test and enable that flag, and just 
use that if available.

Now that's a good point that if we have clock_nanosleep() on another platform 
(non-Linux) and it does the wrong thing, then I might have to add further 
discrimination.

For now, one sticking point that I've stumbled across is that clock_nanosleep() 
requires -lrt. Complicates the autoconf check a bit.

--

___
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



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

2014-04-26 Thread STINNER Victor

STINNER Victor added the comment:

2014-04-27 2:26 GMT+02:00 Shankar Unni rep...@bugs.python.org:
 If you want to modify time.sleep(), you must be careful of the portability: 
 Windows, Linux, but also Mac OS X, FreeBSD, Solaris, etc.

 Oh, I totally agree. What I'm trying to do is to define another autoconf flag 
 (HAVE_CLOCK_NANOSLEEP), that does a feature test and enable that flag, and 
 just use that if available.

I'm talking about the expected behaviour which can be found in the
documentation of the function:
https://docs.python.org/dev/library/time.html#time.sleep

--

___
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



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

2014-04-19 Thread akira

Changes by akira 4kir4...@gmail.com:


--
nosy: +akira

___
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



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

2014-04-18 Thread Shankar Unni

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



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

2014-04-18 Thread Yury Selivanov

Changes by Yury Selivanov yselivanov...@gmail.com:


--
nosy: +haypo, yselivanov

___
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



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

2014-04-18 Thread Shankar Unni

Shankar Unni added the comment:

I'm working on a patch, but I noticed a similar issue in Condition.wait(), 
which also keeps re-evaluating the remaining sleep time based on the current 
kernel clock, with similar effects.

I'll try to address both issues, or we could open a separate bug for the 
latter..

--

___
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