Use python select kqueue on OSX to monitor file creation by external application

883 views Asked by At

Typically the transcode of my 1 hr long audio recording sessions to an mp3 file takes twenty odd minutes.

I want to use a python script to execute a series of python code when the OSX application garageband finishes writing that mp3 file.

What are the best ways in python to detect that an external application is done writing data to a file and closed that file. I read about kqueue and epoll, but since I have no background in os event detection and couldnt find a good example I am asking for one here.

The code I am using right now does the following and I am looking for something more elegant.

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"
1

There are 1 answers

1
Matt Billenstein On

You could popen lsof and filter by either the process or file you're interested in...