linux os.rename() not an actual rename?

Christian Heimes christian at python.org
Mon Jul 20 20:58:24 CEST 2015


On 2015-07-20 20:50, Marko Rauhamaa wrote:
> "Jason H" <jhihn at gmx.com>:
> 
>> I have a server process that looks (watches via inotify) for files to
>> be moved (renamed) into a particular directory from elsewhere on the
>> same filesystem. We do this because it is an atomic operation, and our
>> server process can see the modify events of the file being written
>> before it is closed. The rename functions as a 'completed' event. We
>> have a python script that attempts to perform this behavior - to
>> os.rename() a file into the watched directory after it is done being
>> written. However unlike other tools, we don't see a proper 'rename'
>> event. Instead we just see a 'changed' event. I've changed the
>> implementation of the script to os.system('mv ...') and we get the
>> expected 'rename' event.
> 
> Don't know about inotify(). However, strace reveals that python3's
> os.rename() performs a regular rename(2) system call.

So does Python 2.7:

$ touch test
$ strace -e trace=file -- python -c 'import os; os.rename("test", "test2")'
execve("/bin/python", ["python", "-c", "import os; os.rename(\"test\",
\"te"...], [/* 76 vars */]) = 0
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
...
rename("test", "test2") = 0
+++ exited with 0 +++




More information about the Python-list mailing list