Here's the simplified example. I have this code:
from pygame import mixer
def say():
mixer.init()
mixer.music.load('/home/orif/Downloads/english.wav')
mixer.music.play()
while mixer.music.get_busy():
time.sleep(0.2)
It displays some warnings but works perfectly. The warnings:
ALSA lib pcm_dsnoop.c:606:(snd_pcm_dsnoop_open) unable to open slave ALSA lib pcm_dmix.c:1029:(snd_pcm_dmix_open) unable to open slave ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side ALSA lib pcm_dmix.c:1029:(snd_pcm_dmix_open) unable to open slave
But if I run it in child process it won't:
def test():
talk_process = Process(target=say)
talk_process.start()
print 'waiting for the process...'
talk_process.join()
print 'done'
It prints the same warnings, then:
waiting for the process...
Process Process-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "/home/orif/Projects/example.py", line 178, in say
mixer.init()
error: No available audio device
done
If I do the same but with threading, it runs fine. I have tried what's written here and here. In the former link the solution in the comments almost helped me. I initialized mixer just before running the subprocess:
mixer.init()
talk_process.start()
But now the sound doesn't play, and the waiting loop while mixer.music.get_busy()
is endless
What is happening and how to solve it?