Open janssen opened 8 years ago
I can reproduce your behavior, I've edited your example a bit so it's easier to compare results.
from kivy.base import EventLoop
from kivy.clock import Clock
from kivy.core.window import Window
import time
def callback2(*args):
second = time.time()
print('2', second - start)
def callback1(*args):
first = time.time()
print('1', first - start)
Clock.schedule_once(callback2, 2.0)
start = time.time()
Clock.schedule_once(callback1, 3.0)
EventLoop.run()
1 2.1312689781188965
2 4.134382009506226
I looked at the code, but I couldn't see anything obvious. I was testing on Darwin.
I'm on Windows, it's probably universal.
Can you test with Clock.get_time() instead of time.time().
That would be a more accurate time as it starts from when the Kivy.Clock initiates i.e after the event loop initiates. As time.time() is from when python time instance started
Using https://kivy.org/docs/api-kivy.clock.html#kivy.clock.ClockBase.get_boottime
Running the following example::
from kivy.base import EventLoop
from kivy.clock import Clock
from kivy.core.window import Window
def callback2(*args):
print('2', Clock.get_boottime())
def callback1(*args):
print('1', Clock.get_boottime())
Clock.schedule_once(callback2, 2.0)
Clock.schedule_once(callback1, 3.0)
EventLoop.run()
I get::
('1', 2.99849796295166)
('2', 4.9996349811553955)
That program hide the problem, though. The problem is that the first schedule_once does not get triggered 3 seconds after it's set. Even if you use Clock.get_boottime(). Here's another example:
import time
from kivy.base import EventLoop
from kivy.clock import Clock
from kivy.core.window import Window
def callback2(*args):
global starttime
print('2', Clock.get_boottime(), time.time() - starttime)
EventLoop.quit = True
def callback1(*args):
global starttime
print('1', Clock.get_boottime(), time.time() - starttime)
Clock.schedule_once(callback2, 2.0)
starttime = time.time()
print('0', Clock.get_boottime(), starttime)
Clock.schedule_once(callback1, Clock.get_boottime() + 3.0)
EventLoop.run()
With this, I get:
('0', 0.0, 1459278846.490209)
('1', 3.0041370391845703, 2.559940814971924)
('2', 5.008002996444702, 4.563763856887817)
I've been told that scheduling before the event loop is started could be unsafe, we should also look into that.
Let's reopen this, if the behavior turns out to be expected, we could document it.
We had a discussion with the team, @akshayaurora and @Kovak proposed to explicitly drop schedules created before the clock has started.
When is the clock started? When EventLoop.run() is called? Can you then schedule something after you've called it? And, out of curiosity, why doesn' t this odd behavior happen if you register a user event listener, instead of loading Window?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I'm trying to use Clock to schedule my app startup after the display of an animated splash screen, but the timing of schedule_once() seems almost random.
Here's a program that illustrates the buggy behavior:
Here's a run of this simple program. Note that the first callback is supposed to occur after 3 seconds, but actually occurs after about 1.8 seconds.
If we replace Window with a simple dummy event listener:
the timing is more or less what we expect: