This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Undocumented behavior of sleep functions and asyncio delayed execution
Type: behavior Stage:
Components: Documentation, Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Josef Havránek, asvetlov, docs@python, yselivanov
Priority: normal Keywords:

Created on 2021-04-12 22:11 by Josef Havránek, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg390914 - (view) Author: Josef Havránek (Josef Havránek) Date: 2021-04-12 22:11
Hi i found undocumented behavior of time.sleep, and call_at / call_later from asyncio loop


There are two things to properly document/consider.
It is time of delay/sleep when time for python stops  (aka computer is going to hibernate/Cpu not runing) because time is relative from view of RTC(real time clock) and program both is correct 

curent behavior on
Python 3.9.4 (tags/v3.9.4:1f2e308, Apr  6 2021, 13:40:21) [MSC v.1928 64 bit (AMD64)] on win32

There is  time.sleep , asyncio.sleep and call_later 
They stall for time that has pased for program not on RTC (so it may take time) they not resume when time already passed in real word

then there is loop.call_at

there in in doc  two kinda contradicadictory statements.
and that is 
"This method’s behavior is the same as call_later()"

"and Schedule callback to be called at the given absolute timestamp when (an int or a float), using the same time reference as loop.time()."

thing is it should be legal acording to 1st qoute use
loop.call_at(seconds_to_sleep, lambda:print("something usefull")

but acording to 2nd we should use 
loop.call_at(seconds_to_sleep+loop.time(), lambda:print("something usefull")

and They Both execute after seconds_to_sleep! this is a bug because time to sleep cant be bigger than curent loop.time() then it would execute at incorect time.


Also there is second bug
loop.call_at(seconds_to_sleep+loop.time(), lambda:print("something usefull")

Even this is acording to me(how i understood from doc correct usage)
This will efectively behave as call_later because it will not call callback when seconds_to_sleep already passed since submission

however using
loop.call_at(seconds_to_sleep, lambda:print("something usefull")
will invoke as soon as program resumed from hybernation/when missed

i think loop.call_at(seconds_to_sleep, lambda:print("something usefull") should not wait seconds_to_sleep when it is smaller then loop.time() and just execute it
History
Date User Action Args
2022-04-11 14:59:44adminsetgithub: 87987
2021-04-16 20:27:09terry.reedysetnosy: + asvetlov, yselivanov

versions: - Python 3.6, Python 3.7
2021-04-12 22:11:20Josef Havránekcreate