I needed a mechanism in Python using which I could detect whether a file is open by some other application or not. For Windows, a solution which worked for me was trying to rename the file. Windows doesn’t allow you to rename a file if its still open by some other application.
Unfortunately this didn’t work on a Mac. Mac OS X allows you to rename a file while it is open by some other application. It seems to be a useful feature purposely built into the system (see “Rename open files”).
What could be an alternative solution for Mac OS X so that I could figure out whether any application is holding a file or not?
Try
os.openwithO_EXLOCKflag.This might be not a general solution, but it should work on Unix like systems, including Mac.