I\'m using pyinotify to watch a folder for when files are created in it. And when certain files are created I want to move them. The problem is that as soon as the file is c
It is quite difficult to tell at this level if a file is being written to. What you can do is test to see if a file is opened by some other process.
1) From the various flags that are used while opening a file, O_EXLOCK flag might be of help. If the O_EXLOCK flag is set, the file descriptor has an exclusive lock on the file. So my understanding is if you can do os.open() with O_EXLOCK flag, it's not open by other process. This should work on all posix compatible OS but I have not tested it. If the file, is open then you could close, wait and retry again.
2) You can also try os.stat and see changing time stamp and try to safely interpret the information. Though this is not fool proof.
3) On unix systems, you can try "lsof"
4) The following page describes use of symlinks from /proc/PID/fd to test for open files
[Edit : Links updated]