Starting and stopping a background process

P

Paul Hampton

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top