For a conceptual explanation of Atomic and cross filesystem moves, refer this moves in Python ( can really save your time)
You can take the following approaches to deal with your problem:-
->Monitor Filesystem Events with Pyinotify usage of Pynotify
-> Lock the file for few seconds using flock
-> Using lsof we can basically check for the processes that are using a particular file.
`from subprocess import check_output,Popen, PIPE
try:
lsout=Popen(['lsof',filename],stdout=PIPE, shell=False)
check_output(["grep",filename], stdin=lsout.stdout, shell=False)
except:
#check_output will throw an exception here if it won't find any process using that file`
just write your log processing code in the except part and you are good to go.
-> a daemon that monitors the parent folder for any changes, by using, E.G., the watchdog library watchdog implementation
-> You can either check the file which is being used by another process by looping through the PID/s in /proc for a specific id (assuming you have the control over the program which is adding the new files continuously to identify its id).
-> Can check if a file has a handle on it using psutil.
rename
to atomically move it to the final location where the Python program expects it.mv
makes use ofrename(2)
to "move" files (as documented on the man page you found); likewise Python'sos.rename
call should function similarly as documented, with the additional Python datatypes being supported, which the interpreter will unwrap into the native binary type before making the appropriate system call(s).mv
= linuxrename
= pythonos.rename
but does not equal pythonshutil.move