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
|