Posts: 192
Joined: Wed Nov 26, 2014 5:13 pm

cumulative time error

Sun Oct 14, 2018 5:10 pm

I need to run a function 10 times a second in tkinter. Presently I use root.after(100, update_my_readings)

However, I bet after 1000000 cycles, it will be off due to cumulative error (say each was 99.83 ms). What matters is not that it is exactly 100ms each time, but that it stays in synch with the system time (within the second). Is this the best way to stay in sync with the system clock (such as 12:03:48) ?

I suppose I really want something to happen every 100ms of the system clock...but don't know how that's done using root.after.

Posts: 198
Joined: Wed Dec 14, 2016 10:47 am
Location: Germany

Re: cumulative time error

Mon Oct 22, 2018 8:29 pm

You could install a cron job which runs every minute. The cron job triggers your task for a fixed number of times (600) using root.after or such. Make the after period a little smaller than 100 ms such that your tasks takes only 59.x seconds for its 600 executions.
Same principles as here https://en.wikipedia.org/wiki/Swiss_railway_clock

There are alternative ways like busy-waiting for the wall-clock.

hth KnarfB

Return to “General discussion”