Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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"
like image 563
harijay Avatar asked Jan 31 '26 19:01

harijay


1 Answers

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

like image 161
Matt Billenstein Avatar answered Feb 02 '26 09:02

Matt Billenstein