Probability of IOError during printing and writing
I recently encountered writing an IOError to a file on NFS. There was no disk space or resolution, so I'm guessing this is just a network hiccup. The obvious solution is to wrap the write in try-except, but I was curious if the Python print and write implementation makes one of the following more or less likely to raise the IOError:
f_print = open('print.txt', 'w')
print >>f_print, 'test_print'
f_print.close()
against.
f_write = open('write.txt', 'w')
f_write.write('test_write\n')
f_write.close()
(If it matters, especially in Python 2.4 on Linux).
a source to share
fingerprints are implemented in terms of writes that ultimately lead to a write (2) call to the kernel. You can run strace
on these two samples and (after going through a lot of chaff) see the same resulting calls to write (2).
Indeed, I just did this and omit 2000 lines of output:
execve("/usr/bin/python", ["python", "a.py"], [/* 43 vars */]) = 0
open("print.txt", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 3
write(3, "test_print\n", 11) = 11
close(3) = 0
and
execve("/usr/bin/python", ["python", "b.py"], [/* 43 vars */]) = 0
open("write.txt", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 3
write(3, "test_write\n", 11) = 11
close(3) = 0
there are not many differences to see. If the destination file is on a local disk or NFS mount, the write () call will be the same. The often called Nightmare filesystem will - all things being equal - fail more often than your local drive.
a source to share