I'm trying to start a background process to monitor the audio and am
using pyaudio to accomplish it. I started with a separate script, but
decided it seemed simpler to move the code into my module.

The issue is that once I call the p.open to create the stream the
subprocess hangs and I never get the pid back. If I remove the "stream
=" line then it works fine.

I started out thinking this was a python issue, but when I test
outside of web2py (snip out the appropriate functions and run via cli)
it works fine.

from subprocess import *
from multiprocessing import Process, Queue

        def listener(self, q):
            CHANNELS = 2
            RATE = 44100
            INPUT_BLOCK_TIME = 0.05
            FORMAT = pyaudio.paInt16
            RATE = 44100
            INPUT_FRAMES_PER_BLOCK = int(RATE*INPUT_BLOCK_TIME)

            p = pyaudio.PyAudio()
            stream = p.open(format = FORMAT,
                        channels = CHANNELS,
                        rate = RATE,
                        input = True,
                        frames_per_buffer = INPUT_FRAMES_PER_BLOCK)
            q.put(os.getpid())
            import time
            time.sleep(300)


        def startListener(self):
            q = Queue()
            p = Process(target=self.listener, args=[q])
            p.daemon=True
            p.start()
            print q.get()

Is there something about threading or modules that prevents this from
working in web2py?

Any help is appreciated!

Reply via email to