I have a class showAllThreads that monitors all the existing threads in the script (music player)
class showAllThreads(threading.Thread):
def __init__(self, *args, **kwargs):
threading.Thread.__init__(self, *args, **kwargs)
self.daemon = True
self.start()
#Shows whether the playing music is in queue, initially false
musicQueue = False
def run(self):
while True:
allThreads = threading.enumerate()
for i in allThreads:
if i.name == "PlayMusic" and i.queue == True:
musicQueue = True
print("Playlist is on")
elif i.name == "PlayMusic" and i.queue == False:
musicQueue = False
print("Playlist is off")
else:
musicQueue = False
time.sleep(2)
When I try to access musicQueue from the mainthread by allThreads.musicQueue where allThreads = showAllThreads()it always gives me value False, even though the while loop executes musicQueue = True. I know that the playlist is on, because the print command excecutes successfully.