Status of side-effecting functions in python

Marko Rauhamaa marko at
Mon Oct 27 16:14:58 CET 2014

Grant Edwards <invalid at invalid.invalid>:

> If you really want to make sure that all bytes get written, you _must_
> put all write() calls in a loop that checks the return value and keeps
> re-writing any unwritten data.
> And to answer your next question: yes, Unix application programmers
> have been complaining about that (perhaps justifiably) since 1970.

I wouldn't have it any other way.

Now, I have confused the discussion with some misinformation myself.
Python2's file.write() doesn't return a value but pushes the whole
string out. Python3's file.write() returns the number of *characters*
written. I don't know if the number can ever be different from the total
number of characters in the string.

In POSIX, a write(2) system call on file blocks until all bytes have
been passed on to the file system. The only exception (no pun intended)
I know is the reception of a signal. Even then, I'm not sure Linux file
systems ever cut writes short because of signals. I think the lack of
nonblocking file access in Linux is one of the OS's main shortcomings.

Python's sockets and pipes don't have write methods.


More information about the Python-list mailing list