Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Playsound does not work with multiprocessing

I want to use multiprocessing to play and stop a sound file at any time, but when I start the process no sound was played.

from multiprocessing import Process
from playsound import playsound

    
def sound():
    playsound('sound.mp3')


p = Process(target=sound)
p.start()

When I tried using sound() on its own it works perfectly fine, but with multiprocessing it doesn’t work.

Even if I add p.join(), the code just finishes as soon as I start it, no sound gets played, and no error message is shown in the IDLE Shell.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How can I fix this?

>Solution :

Putting the execution code inside the "if" clause as below solved the problem on my computer.
If this does not work for you, please explain the situation more in detail, e.g. how you are running the code, your OS, Python version, etc.

from multiprocessing import Process
from playsound import playsound

    
def sound():
    playsound('sound.mp3')

if __name__ == "__main__":
    p = Process(target=sound)
    p.start()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading