Starting and stopping a background process

Paul Hampton phampton at eso.org
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):
         threading.Thread.__init__(self)
 

     def run(self):
         self.recording_threaded()
 

     def recording_threaded(self):
         popup_string="Recording Audio Stream"
         pop = PopupBox(text=popup_string)
         pop.show()
         time.sleep(4)
         pop.destroy()
         print "Recording"
         time.sleep(20)
         recording=1
         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)
         pop.show()
         time.sleep(4)
         pop.destroy()
         print "Recording Stopped"
         recording=0
         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
Paul





More information about the Python-list mailing list