Mailing List Archive

[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux
Change by Roundup Robot <devnull@psf.upfronthosting.co.za>:


----------
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 <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
Change by Benjamin Sz?ke <egyszeregy@freemail.hu>:


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

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
Benjamin Sz?ke <egyszeregy@freemail.hu> added the comment:

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

----------
versions: +Python 3.11

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
STINNER Victor <vstinner@python.org> 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 <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
Change by STINNER Victor <vstinner@python.org>:


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

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
STINNER Victor <vstinner@python.org> 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 <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
Change by Benjamin Sz?ke <egyszeregy@freemail.hu>:


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

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
Change by STINNER Victor <vstinner@python.org>:


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

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
STINNER Victor <vstinner@python.org> 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 <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
STINNER Victor <vstinner@python.org> 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 <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
Change by STINNER Victor <vstinner@python.org>:


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

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
STINNER Victor <vstinner@python.org> 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 <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
STINNER Victor <vstinner@python.org> 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 <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
STINNER Victor <vstinner@python.org> 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 <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
STINNER Victor <vstinner@python.org> 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 <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
STINNER Victor <vstinner@python.org> added the comment:

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

----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
STINNER Victor <vstinner@python.org> added the comment:

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

----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
Change by Benjamin Sz?ke <egyszeregy@freemail.hu>:


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

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
Change by STINNER Victor <vstinner@python.org>:


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

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
STINNER Victor <vstinner@python.org> 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 <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
STINNER Victor <vstinner@python.org> added the comment:

Thanks Livius for all these nice enhancements!

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

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
Benjamin Sz?ke <egyszeregy@freemail.hu> added the comment:

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

----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
STINNER Victor <vstinner@python.org> 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 <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
Benjamin Sz?ke <egyszeregy@freemail.hu> 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 <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue21302] time.sleep (floatsleep()) should use clock_nanosleep() on Linux [ In reply to ]
STINNER Victor <vstinner@python.org> 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 <report@bugs.python.org>
<https://bugs.python.org/issue21302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

1 2  View All