python, threading and a radio timer

Discussion in 'Python' started by Renato, Oct 31, 2006.

  1. Renato

    Renato Guest

    Dear all,

    I found this nifty article on how to record your favourite radio show
    using cron and mplayer:
    http://grimthing.com/archives/2004/05/20/recording-streaming-audio-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
     
    Renato, Oct 31, 2006
    #1
    1. Advertising

  2. Renato

    ArdPy Guest

    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/05/20/recording-streaming-audio-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.
     
    ArdPy, Oct 31, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kelsang Wangchuk

    System.Timers.Timer vs. System.Threading.Timer

    Kelsang Wangchuk, Jul 31, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    731
    Kelsang Wangchuk
    Jul 31, 2003
  2. Replies:
    1
    Views:
    1,641
    Steve C. Orr [MVP, MCSD]
    Feb 22, 2005
  3. Stig Hausberg

    System.Threading.Timer and Dotnet 2.0

    Stig Hausberg, May 12, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    6,845
    amar_kumar
    Aug 3, 2007
  4. Simon

    page timer, or redirect timer

    Simon, Nov 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    11,234
    Bruce Barker
    Nov 4, 2005
  5. Replies:
    8
    Views:
    570
    Jorgen Grahn
    Jul 15, 2013
Loading...

Share This Page