Essentially, I have a GUI based program (Tkinter) and I am using multiple threads to update the values and do other stuff. With this, I have a global variable I want to share between threads, as one will update the changing value (thread1) and the other will use that same value to do its own thing in some loops in thread2. With thread2, I want this to run forever, constantly checking this value to the set number of <40 or >40. I've determined that the increase in memory comes from thread2, as commenting the thread out makes the program run without a significant memory increase. and it has nothing to do with the vlc objects, to me it seems like its the global variable or it being in an infinite loop.
Here is simplified code and the full code for thread2. I plan on running this on a rpi and over 2 minutes it gains about 1GB of consumed memory.
Any help is greatly appriciated. Thanks!!
(import vlc and others)
globalVar = 0.0
def Thread1():
global globalVar
#...modifies globalVar and GUI values
def Thread2():
nowPlaying = vlc.MediaPlayer("song1.mp3")
nowPlaying.play()
changePlaying = vlc.MediaPlayer("song2.mp3")
while True:
extra = 0
caseNum = random.randint(1,3)
if caseNum == 1:
eurobeat = vlc.MediaPlayer("song4.mp3")
elif caseNum == 2:
eurobeat = vlc.MediaPlayer("song5.mp3")
elif caseNum == 3:
eurobeat = vlc.MediaPlayer("song6.mp3")
while globalVar >= 40:
extra = extra + 1
nowPlaying.set_pause(1)
if (changePlaying.is_playing()) == 0:
changePlaying.play()
if extra > 2:
time.sleep(3)
time.sleep(3)
if globalVar < 40:
nowPlaying.set_pause(0)
changePlaying.stop()
changePlaying.stop()
thread1 = Thread(target=Thread1)
thread1.setDaemon(True)
thread1.start()
thread2 = Thread(target=Thread2)
thread2.setDaemon(True)
thread2.start()
(tkinter)
root.mainloop()