Closed yumedzi closed 7 years ago
Yep you're right. I didn't pick this up in development since I normally have a fast-running timer doing drawing, and then slow timers doing background updates etc.
BTW: 👌 a perfect pull request! One line change, accompanied with a well reasoned explanation and sample code!
FYI, I made a few more changes after this - one was to change this scheduling behaviour slightly, so that delays in any timers didn't affect the scheduling too much. See 9a172376d7147e9024cac74d0d9ef92ced436f06.
Released as tingbot-python v1.0.0 on PyPI. Will be in the next version of Tide.
The idea is to fix RunLoop.run() method to correctly schedule next time to run the processed timer. It should be based on the time of last run not a previous one. Currently because of we use
start_time
as the base time for this we are getting timer ran two times in the same period of time:self._wait(next_timer.next_fire_time)
.next_timer.next_fire_time = start_time + next_timer.period
because we already waitednext_timer.period
sostart_time + next_timer.period
would be right now.To get more understanding consider this example:
This loop will generate the following output:
showing that loop will be fired two times after 5 seconds each time. The same behaviour for minutes and multiple scheduled timers.