0
我有一個類showAllThreads
監視所有現有的線程在腳本(音樂播放器)變量Thread類沒有顯示正確的輸出(蟒蛇)
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)
當我嘗試通過allThreads.musicQueue
從mainthread訪問musicQueue
其中allThreads = showAllThreads()
即使while循環執行musicQueue = True
,它總是給我值False
。我知道播放列表已打開,因爲打印命令可以成功執行。