I have a simple tool which is crashing every few days. I simplified it to show the problem.
Short description:
A counter is incremeted and displayed with Tk as a Label.
Problem:
There must be a memory leak - with this demo script I can crash a 1 GB Raspberry in 5 - 10 minutes...
The problem is the label-update (labeltext.set(counter))
Without updating the label it works for hours without a problem.
But why? I really don't understand it...
Thank you.
from tkinter import *
root = Tk()
counter=1
labeltext = StringVar()
root.config(cursor="none")
root.configure(background='black')
root.geometry("1920x1080") # set explicitly window size
frame_0= Frame(root, padx=5, pady=5, background='black' )
label1 = Label(frame_0, font=('LCD Display Grid', 170, ''), fg='lightgreen',bg='black', pady=30, textvariable=labeltext)
frame_0.grid( row=0, columnspan=3,pady=10, padx=0)
label1.pack()
root.grid_columnconfigure(0, weight=1)
class perpetualTimer():
def __init__(self, t, hFunction):
self.t = t
self.hFunction = hFunction
self.thread = Timer(self.t, self.handle_function)
def handle_function(self):
self.hFunction()
self.thread = Timer(self.t, self.handle_function)
self.thread.start()
def start(self):
self.thread.start()
def cancel(self):
self.thread.cancel()
def printer():
global counter
counter = counter + 1
labeltext.set(counter)
t = perpetualTimer(0.001, printer)
t.start()
root.mainloop()