Bonjour
J’ai un très gros problème de fuite de mémoire lorsque je fais varier 40 valeurs toutes les ½ secondes dans une fenêtre Tkinter.
J’ai 40 DoubleVar avec 40 labels. Les labels sont relié par TextVariable.
La fuite est de l’ordre 100Mo par heures.
Tkinter est il pas adapté a ce fonctionnement? Après une recherche, il semblerai que la bibliothèque " Libavg " serait fait pour des taches rapides. Quand pensez-vous?
(J’ai pas fait d’optimisation par boucle for ou autre, pour faire des tests trés trés simple)
Voici le code en entier :
from threading import Timer
import tkinter as Tk
import time
class RepeatedTimer(object):
def init(self, interval, function, *args, **kwargs):
self._timer = None
self.interval = interval
self.function = function
self.args = args
self.kwargs = kwargs
self.is_running = False
self.start()
def _run(self):
self.is_running = False
self.start()
self.function(*self.args, **self.kwargs)
def start(self):
if not self.is_running:
self._timer = Timer(self.interval, self._run)
self._timer.start()
self.is_running = True
def stop(self):
self._timer.cancel()
self.is_running = False
fenetreSupport = Tk.Tk()
fenetreSupport.title(« Fenetre »)
fenetreSupport.configure(bg=« white »)
fenetreSupport.geometry(« 1000x1000+100+100 »)
VarnN01 = Tk.DoubleVar()
VarnN02 = Tk.DoubleVar()
VarnN03 = Tk.DoubleVar()
VarnN04 = Tk.DoubleVar()
VarnN05 = Tk.DoubleVar()
VarnN06 = Tk.DoubleVar()
VarnN07 = Tk.DoubleVar()
VarnN08 = Tk.DoubleVar()
VarnN09 = Tk.DoubleVar()
VarnN10 = Tk.DoubleVar()
VarnN11 = Tk.DoubleVar()
VarnN12 = Tk.DoubleVar()
VarnN13 = Tk.DoubleVar()
VarnN14 = Tk.DoubleVar()
VarnN15 = Tk.DoubleVar()
VarnN16 = Tk.DoubleVar()
VarnN17 = Tk.DoubleVar()
VarnN18 = Tk.DoubleVar()
VarnN19 = Tk.DoubleVar()
VarnN20 = Tk.DoubleVar()
VarnN21 = Tk.DoubleVar()
VarnN22 = Tk.DoubleVar()
VarnN23 = Tk.DoubleVar()
VarnN24 = Tk.DoubleVar()
VarnN25 = Tk.DoubleVar()
VarnN26 = Tk.DoubleVar()
VarnN27 = Tk.DoubleVar()
VarnN28 = Tk.DoubleVar()
VarnN29 = Tk.DoubleVar()
VarnN30 = Tk.DoubleVar()
VarnN31 = Tk.DoubleVar()
VarnN32 = Tk.DoubleVar()
VarnN33 = Tk.DoubleVar()
VarnN34 = Tk.DoubleVar()
VarnN35 = Tk.DoubleVar()
VarnN36 = Tk.DoubleVar()
VarnN37 = Tk.DoubleVar()
VarnN38 = Tk.DoubleVar()
VarnN39 = Tk.DoubleVar()
widthLocal = 150
frameSupport = Tk.Frame(fenetreSupport, bg=« red »,width=10, height=10 )
canvas = Tk.Canvas(frameSupport, width=10, height=10, bg=« silver » )
LabelN01 = Tk.Label(canvas, textvariable=VarnN01, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN01.pack()
LabelN02 = Tk.Label(canvas, textvariable=VarnN02, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN02.pack()
LabelN03 = Tk.Label(canvas, textvariable=VarnN03, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN03.pack()
LabelN04 = Tk.Label(canvas, textvariable=VarnN04, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN04.pack()
LabelN05 = Tk.Label(canvas, textvariable=VarnN05, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN05.pack()
LabelN06 = Tk.Label(canvas, textvariable=VarnN06, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN06.pack()
LabelN07 = Tk.Label(canvas, textvariable=VarnN07, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN07.pack()
LabelN08 = Tk.Label(canvas, textvariable=VarnN08, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN08.pack()
LabelN09 = Tk.Label(canvas, textvariable=VarnN09, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN09.pack()
LabelN10 = Tk.Label(canvas, textvariable=VarnN10, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN10.pack()
LabelN11 = Tk.Label(canvas, textvariable=VarnN11, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN11.pack()
LabelN12 = Tk.Label(canvas, textvariable=VarnN12, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN12.pack()
LabelN13 = Tk.Label(canvas, textvariable=VarnN13, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN13.pack()
LabelN14 = Tk.Label(canvas, textvariable=VarnN14, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN14.pack()
LabelN15 = Tk.Label(canvas, textvariable=VarnN15, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN15.pack()
LabelN16 = Tk.Label(canvas, textvariable=VarnN16, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN16.pack()
LabelN17 = Tk.Label(canvas, textvariable=VarnN17, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN17.pack()
LabelN18 = Tk.Label(canvas, textvariable=VarnN18, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN18.pack()
LabelN19 = Tk.Label(canvas, textvariable=VarnN19, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN19.pack()
LabelN20 = Tk.Label(canvas, textvariable=VarnN20, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN20.pack()
LabelN21 = Tk.Label(canvas, textvariable=VarnN21, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN21.pack()
LabelN22 = Tk.Label(canvas, textvariable=VarnN22, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN22.pack()
LabelN23 = Tk.Label(canvas, textvariable=VarnN23, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN23.pack()
LabelN24 = Tk.Label(canvas, textvariable=VarnN24, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN24.pack()
LabelN25 = Tk.Label(canvas, textvariable=VarnN25, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN25.pack()
LabelN26 = Tk.Label(canvas, textvariable=VarnN26, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN26.pack()
LabelN27 = Tk.Label(canvas, textvariable=VarnN27, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN27.pack()
LabelN28 = Tk.Label(canvas, textvariable=VarnN28, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN28.pack()
LabelN29 = Tk.Label(canvas, textvariable=VarnN29, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN29.pack()
LabelN30 = Tk.Label(canvas, textvariable=VarnN30, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN30.pack()
LabelN31 = Tk.Label(canvas, textvariable=VarnN31, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN31.pack()
LabelN32 = Tk.Label(canvas, textvariable=VarnN32, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN32.pack()
LabelN33 = Tk.Label(canvas, textvariable=VarnN33, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN33.pack()
LabelN34 = Tk.Label(canvas, textvariable=VarnN34, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN34.pack()
LabelN35 = Tk.Label(canvas, textvariable=VarnN35, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN35.pack()
LabelN36 = Tk.Label(canvas, textvariable=VarnN36, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN36.pack()
LabelN37 = Tk.Label(canvas, textvariable=VarnN37, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN37.pack()
LabelN38 = Tk.Label(canvas, textvariable=VarnN38, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN38.pack()
LabelN39 = Tk.Label(canvas, textvariable=VarnN39, text=« nan »,width =widthLocal, height=1, relief = ‹ groove ›)
LabelN39.pack()
Val = -1
def LectureCyclique(Name):
global Val
Val += 1
VarnN01.set(Val + 1)
VarnN02.set(Val + 2)
VarnN03.set(Val + 3)
VarnN04.set(Val + 4)
VarnN05.set(Val + 5)
VarnN06.set(Val + 6)
VarnN07.set(Val + 7)
VarnN08.set(Val + 8)
VarnN09.set(Val + 9)
VarnN10.set(Val + 10)
VarnN11.set(Val + 11)
VarnN12.set(Val + 12)
VarnN13.set(Val + 13)
VarnN14.set(Val + 14)
VarnN15.set(Val + 15)
VarnN16.set(Val + 16)
VarnN17.set(Val + 17)
VarnN18.set(Val + 18)
VarnN19.set(Val + 19)
VarnN20.set(Val + 20)
VarnN21.set(Val + 21)
VarnN22.set(Val + 22)
VarnN23.set(Val + 23)
VarnN24.set(Val + 24)
VarnN25.set(Val + 25)
VarnN26.set(Val + 26)
VarnN27.set(Val + 27)
VarnN28.set(Val + 28)
VarnN29.set(Val + 29)
VarnN30.set(Val + 30)
VarnN31.set(Val + 31)
VarnN32.set(Val + 32)
VarnN33.set(Val + 33)
VarnN34.set(Val + 34)
VarnN35.set(Val + 35)
VarnN36.set(Val + 36)
VarnN37.set(Val + 37)
VarnN38.set(Val + 38)
VarnN39.set(Val + 39)
RepeatedTimerVar = RepeatedTimer(0.5, LectureCyclique, « LectureCyclique »)
canvas.pack()
frameSupport.pack()
fenetreSupport.mainloop()
RepeatedTimerVar.stop()