Home » Python » python – pyaudio freezing program in multiprocess with wxPython-Exceptionshub

python – pyaudio freezing program in multiprocess with wxPython-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

Calling p = pyaudio.PyAudio() in my app causes it to freeze when it’s called inside of a multiprocess. Note I’m running the app with pythonw instead of python. When I remove the wx modules, it works fine. Any suggestions on how to fix? I’m using python 3.5 on MacOS

from app import frame, app
import pyaudio
import time
import multiprocessing as mp

def worker():
    p = pyaudio.PyAudio()
    while True:
        print('starting worker')
        print('pyaudio', p)
        time.sleep(1)

if __name__ == '__main__':
    p1 = mp.Process(target=worker)
    p1.start()

    frame.Show()
    app.MainLoop()

    p1.join()

app.py

import wx

app = wx.App()
frame = wx.Frame(parent=None, title='Hello World')


frame.Show()
app.MainLoop()
How to&Answers:

When you import your app module it is executing all the code and blocking at app.MainLoop() while it is processing and dispatching events. Control does not return to your main module until MainLoop returns.