What I want to do is get an audio file to play while a def (function) is running. I've looked it up and seen that threading works but it is wayyyy to complicated for me to work out. Is there a way you guys can explain it to me? I was using winsound to play the audio file, and SND_FILENAME.
Asked
Active
Viewed 47 times
-2
-
Well you do need to use threading – whackamadoodle3000 Aug 01 '18 at 01:12
-
@ᴡʜᴀᴄᴋᴀᴍᴀᴅᴏᴏᴅʟᴇ3000 Thought so, but I have no idea how to use it and the online documents don't help much – Francois van Kempen Aug 01 '18 at 01:15
-
Check this out: https://www.tutorialspoint.com/python/python_multithreading.htm – whackamadoodle3000 Aug 01 '18 at 01:18
-
Thanks! I still have no idea to do this with an audio file. This seems pretty advanced, and I'm only just starting out in python. – Francois van Kempen Aug 01 '18 at 01:33
-
You said you were using winsound to play the audio file, so just plug in that code into the function below (play), and add your other function there too. – whackamadoodle3000 Aug 01 '18 at 01:36
1 Answers
1
Try this:
from multiprocessing import Process
def play():
#winsound stuff
def function():
#functiony stuff
if __name__ == '__main__':
p = Process(target=play)
d = Process(target=function)
p.start()
d.start()

whackamadoodle3000
- 6,684
- 4
- 27
- 44
-
Whenever I do this, I get the following error code: PicklingError: Can't pickle
: it's not found as __main__.play – Francois van Kempen Aug 01 '18 at 03:07 -
Can you show what you put inside play (and if you included parameters)? And also look at https://stackoverflow.com/questions/8804830/python-multiprocessing-pickling-error (where they use pathos). – whackamadoodle3000 Aug 01 '18 at 13:37
-
it's okay, I figured it out myself. Ended up using the module threading, and `p = threading.Thread(target=play)` which worked. – Francois van Kempen Aug 01 '18 at 15:19
-
You sent me on the right track though, so I'll accept your answer. – Francois van Kempen Aug 01 '18 at 15:48