Using select.kqueue to monitor garageband transcode completion

Discussion in 'Python' started by harijay, Jan 25, 2011.

  1. harijay

    harijay Guest

    I want to automate a series of functions in python that trigger when
    the OSX application Garagband finishes writing to a file called
    "todays_recording.mp3".

    A Typical transcode process takes 20 minutes , and I fancy starting
    the python program immediately after I start the transcode and then
    walking away.

    For the present moment I have a silly implementation that does
    something like the code pasted below.

    I was looking online for smarter I/O monitoring and I came across the
    kqueue classes inside of the select module which could be used to
    monitor the kernel events in BSD - so it should work on OSX. However
    being a newbie , I cannot understand how to setup the select.kqueue
    event to look for garageband closing , i.e finish writing the
    transcoded mp3 file.

    I did see some code on comp.lang.python about this in a post from
    Ritesh Nadhani (pasted below as well). But I dont understand what the
    events mean . Looking for help to monitor the file closing using
    select.kqueue.


    Thanks
    Hari



    My Pseudocode for clunky monitoring of file i/o completion:

    while True:
    try:
    today_file = open("todays_recording.mp3","r")
    my_custom_function_to_process_file(today_file)
    except IOError:
    print "File not ready yet..continuing to wait"

    ###############
    Some source code I came across on comp.lang.python ( courtesy Ritesh
    Vadvani) related to this
    ##############

    import select26 as select
    import os

    kq = select.kqueue()
    fd = os.open("/tmp/a.txt", os.O_RDONLY)

    # I dont understand this line below
    ev = [select.kevent(fd, filter=select.KQ_FILTER_VNODE,
    flags=select.KQ_EV_ADD | select.KQ_EV_ENABLE | select.KQ_EV_ONESHOT,
    fflags=select.KQ_NOTE_WRITE | select.KQ_NOTE_DELETE
    | select.KQ_NOTE_EXTEND)]
    kq.control(ev, 0, 0)

    try:
    while True:
    evts = kq.control(ev, 1, None)
    if len(evts):
    print evts
    except KeyboardInterrupt:
    pass
    else:
    kq.close()
    os.close(fd)
     
    harijay, Jan 25, 2011
    #1
    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. Prajakta

    Leaks in XMLString::transcode

    Prajakta, Apr 22, 2004, in forum: XML
    Replies:
    0
    Views:
    2,403
    Prajakta
    Apr 22, 2004
  2. Ritesh Nadhani

    Re: Using select.kqueue()

    Ritesh Nadhani, Sep 3, 2009, in forum: Python
    Replies:
    0
    Views:
    518
    Ritesh Nadhani
    Sep 3, 2009
  3. Ritesh Nadhani

    select.kqueue.control changelist argument

    Ritesh Nadhani, Sep 3, 2009, in forum: Python
    Replies:
    0
    Views:
    312
    Ritesh Nadhani
    Sep 3, 2009
  4. ziggs
    Replies:
    2
    Views:
    208
    Henry Robinson
    Apr 21, 2004
  5. Curt Sampson
    Replies:
    1
    Views:
    149
    Francis Cianfrocca
    Feb 5, 2008
Loading...

Share This Page