The best way to check if a file is locked is to try to lock it. The fcntl module will do this in Python, for example.
fcntl.lockf(fileobj.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
This will increase IOError if the file is already locked; if it is not, you can call
fcntl.lockf(fileobj.fileno(), fcntl.LOCK_UN)
To unlock it again.
: Windows, Unix. , fcntl Windows; os.open, , ( ).
user79758