Hello,
I have recently started learning Python and part of the simple app I am making includes a timer with a hh:mm:ss display running in its own thread.
Looking around the web I found two ways of implementing this:
- Using sched.scheduler
- Using threading.Timer
The way I did it looks similar for both implementations:
sched:
def tick(self, display, alarm_time):
# Schedule this function to run every minute
s = sched.scheduler(time.time, time.sleep)
s.enter(1, 1, self.tick, ([display, alarm_time]))
# Update the time
self.updateTime(display)
Timer:
def tick(self, display):
# Schedule this function to run every second
t = Timer(1, self.tick, (display,alarm_time))
t.start()
# Update the time
self.updateTime(display)
Works fine with regards to ticking correctly, but generates the following error after a few minutes: RuntimeError: maximum recursion depth exceeded. I know you can increase the max recursion level manually, but surely this should not be necessary here?
No error, but occasionally the seconds will skip, or tick irregularly.
Can someone please point me in the right direction as to how to do this correctly? Thank you.