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) -- http://mail.python.org/mailman/listinfo/python-list