multithreading - How to keep a python script open while some C code executes some thread? -


i trying add non-blocking audio i/o pyaudio.

pyaudio relies on portaudio audio i/o. non-blocking audio in portaudio, define callback function when opening audio stream. when audio stream started, call callback function whenever new audio data required.

this part works. test wrote simple script implements callback function looking this:

def pyaudiocallback(framecount,inadctime,curtime,outadctime,userdata,inp = none):     data=getdata(framecount)     return (data,0) 

this callback called whenever audio stream needs new audio samples. however, script not know audio stream still running , terminates whenever done, which, of course, terminates audio stream also.

i can work around issue inserting time.sleep() somewhere. audio playback work fine while script sleeping. however, rather postpone script's completion until audio stream thinks done.

is there way keep python session alive until criteria met? or wait loop option?

several ways.

create pipe. pass read end select.select() no timeout. frob write end when audio done.

acquire semaphore or mutex twice. release when audio done.

and more, won't need.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -