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
。我知道播放列表已打开,因为打印命令可以成功执行。