Starting and stopping a background process

Paul Hampton phampton at
Thu Jul 3 11:58:51 CEST 2003

Hi all

I'm new to python so please be gentle :)

I'm trying to write a module for my media playing PC which will record 
input directly from the soundcard using LAME. At the moment I can get it 
started ok and am about to try and work out the best way to stop the 
process (which is threaded). I could get the process id of LAME and just 
kill it, but I think this is a bit messy. Can anyone give me any 
suggestions on how to make this script determine if lame is already 
running and then stop it if it is, if not then start it? The following 
code is run when a certain key is pressed:

class main_recording_thread(threading.Thread):

     def __init__(self):

     def run(self):

     def recording_threaded(self):
         popup_string="Recording Audio Stream"
         pop = PopupBox(text=popup_string)
         print "Recording"
         os.system("sox -t ossdsp -w -s -r 44100 -c 2 /dev/dsp -t raw - 
|     /usr/local/freevo/runtime/apps/lame -x -m s - ./test.mp3")
         popup_string="Audio Recording Stopped"
         pop = PopupBox(text=popup_string)
         print "Recording Stopped"
         return []

I expect my coding is really bad as it is my second attempt ever at python.

So, what would be the best way to do this start/stop thing?

Thanks in advance

More information about the Python-list mailing list