STINNER Victor added the comment:

"(it's probably broken with non-blocking streams too, for the same
reason)"

Yes it is :-)

We hitted this issue on eventlet when I changed the socket.send() method in 
eventlet 0.18 to stop sending data on partial write, whereas eventlet < 0.18 
used a loop to ensure that all bytes are written.

The side effect of my change is that (indirectly) 
socket.makefile().writelines() may also use partial write if the underlying 
send() only writes partially data.

The problem is that writelines() has *no* result, so the caller cannot be aware 
of the partial write and data is lost...

eventlet:

* send() change: https://github.com/eventlet/eventlet/issues/274
* writelines() bug: https://github.com/eventlet/eventlet/issues/295


"In the spirit of RawIO.write(), I think RawIO.writelines() could return
the number of bytes written (allowing for partial writes)."

I don't know yet what is the best option for eventlet, but we should probaly 
enhance the Python stdlib io module to return something on writelines() and 
*document* the behaviour on partial write.

The problem writelines() API is that writelines() not only takes a single 
text/bytes string, but a *list* of text/bytes strings.

Another option is to modify to retry on partial write to ensure that all data 
is written. If the underlying write() method returns None (blocking I/O error), 
we must raise an error. It doesn't make sense to retry writing on a 
non-blocking I/O error.

In this case, we must document that writelines() *must not* be used on 
non-blocking I/O (ex: non-blocking socket, pipe, whatever).

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26292>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to