I want to detect whether a file is locked, using python on Unix. It\'s OK to delete the file, assuming that it helps detects whether the file was locked.
The file could
From the fcntl docs:
fcntl.lockf(fd, operation[, length[, start[, whence]]])
If LOCK_NB is used and the lock cannot be acquired, an IOError will be raised and the exception will have an errno attribute set to EACCES or EAGAIN (depending on the operating system; for portability, check for both values).
This uses the underlying unix flock
mechanism, so looks like it should do what you want. Also note there is also os.open, which may be more platform-independent.