473,326 Members | 2,438 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

python, threading and a radio timer

Dear all,

I found this nifty article on how to record your favourite radio show
using cron and mplayer:
http://grimthing.com/archives/2004/0...-with-mplayer/

Because I couldn't get the date in the filename (and was too lazy to
look into sh/bash manuals), I decided to use Python. It was a good
choice, because I decided to improve the timer - learning some more
Python along the way!

So, the idea is:
- cron runs the script at a specific time
- the script starts mplayer, and will keep checking the clock until
it's time to kill mplayer
- after mplayer has exited, oggenc is started to turn the raw WAV into
ogg
- and finally the remaining WAV is deleted

This basic setting is quite easy, and I used os.spawnvp(os.P_WAIT,...),
along with another CRON entry to kill mplayer.

But then I got more ambitious: I wanted the script to keep checking if
mplayer was alive - in case the connection goes down. Moreover, I would
rather have the script stop mplayer than cron.

At this point, I thought I should get some professional help... :) What
is the right way to go? Would threads be overkill? If so, where can I
go about looking for process control/management without delving into
complex daemon architectures?

So, rather than asking for code, I'm looking for guidance - this is a
didactic experience!

Cheers,

Renato

Oct 31 '06 #1
1 1432

Renato wrote:
Dear all,

I found this nifty article on how to record your favourite radio show
using cron and mplayer:
http://grimthing.com/archives/2004/0...-with-mplayer/

Because I couldn't get the date in the filename (and was too lazy to
look into sh/bash manuals), I decided to use Python. It was a good
choice, because I decided to improve the timer - learning some more
Python along the way!

So, the idea is:
- cron runs the script at a specific time
- the script starts mplayer, and will keep checking the clock until
it's time to kill mplayer
- after mplayer has exited, oggenc is started to turn the raw WAV into
ogg
- and finally the remaining WAV is deleted

This basic setting is quite easy, and I used os.spawnvp(os.P_WAIT,...),
along with another CRON entry to kill mplayer.

But then I got more ambitious: I wanted the script to keep checking if
mplayer was alive - in case the connection goes down. Moreover, I would
rather have the script stop mplayer than cron.

At this point, I thought I should get some professional help... :) What
is the right way to go? Would threads be overkill? If so, where can I
go about looking for process control/management without delving into
complex daemon architectures?

So, rather than asking for code, I'm looking for guidance - this is a
didactic experience!

Cheers,

Renato
I would suggest you take a look at Python 'commands' module. The module
lets you run Unix commands by taking them as parameters to function
calls. That is all I can say with my level of expertise.

Oct 31 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Jane Austine | last post by:
As far as I know python's threading module models after Java's. However, I can't find something equivalent to Java's interrupt and isInterrupted methods, along with InterruptedException....
3
by: ELO | last post by:
Hi all Every week, I need to get two files on a remote server. I have developped a C# Windows Service with two System.Threading.Timer to do this task For the first one, the delay (TimeSpan...
6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
3
by: mjheitland | last post by:
Hi, I like to know how many threads are used by a Threading.Timer object. When I create a Threading.Timer object calling a short running method every 5 seconds I expected to have one additional...
0
by: Russell Warren | last post by:
I've got a case where I need to tweak the implementation of a default python library due to what I consider to be an issue in the library. What is the best way to do this and make an attempt to...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 380 open (-36) / 3658 closed (+65) / 4038 total (+29) Bugs : 965 open ( -9) / 6555 closed (+35) / 7520 total (+26) RFE : 272 open...
5
by: johnny | last post by:
Is there a way to call a function on a specified interval(seconds, milliseconds) every time, like polling user defined method? Thanks.
7
by: silverburgh.meryl | last post by:
Hi, I am using timeit to time a global function like this t = timeit.Timer("timeTest()","from __main__ import timeTest") result = t.timeit(); But how can i use timeit to time a function...
4
by: Sayanan Sivaraman | last post by:
Hey all, So I've written a simple video player using directshow/COM in VC++, and I'm in the process of translating it to python. For example, when the avi starts playing, I have a call...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.