Python >> Tutoriel Python >  >> Python Tag >> exec()

Python exécute playsound dans un thread séparé

Utiliser la bibliothèque de threads :

from threading import Thread
T = Thread(target=playy) # create thread
T.start() # Launch created thread

Vous n'aurez peut-être pas à vous soucier de l'utilisation d'un fil. Vous pouvez simplement appeler playsound comme suit :

def playy():  
    playsound('beep.mp3', block = False)

Cela permettra au programme de continuer à s'exécuter sans attendre la fin de la lecture du son.