STINNER Victor <vstin...@python.org> added the comment:

cc Antoine Pitrou who was involved in io module design.

Currently, the io.TextIOWrapper implementation doesn't handle partial write: it 
doesn't fully support an unbuffered 'buffer' object.

It should either handle partial write internally, or it should inject a 
buffered writer between itself (TextIOWrapper) and the unbuffered buffer so 
handling partial writes who be handled by the buffered writer.

The socket.socket class has a sendall() method which helps to handle such 
problem. In the io module, sometimes write() can do a partial write (unbuffered 
writer like FileIO), sometimes it doesn't (buffered writer like BufferedWriter).

== C implementation ==

Modules/_io/text.c. The _io_TextIOWrapper_write_impl() function puts the 
encoded string into an internal pending_bytes list. If needed, it calls 
flush(): _textiowrapper_writeflush().

The pseudo-code of _textiowrapper_writeflush() is to call 
"self.buffer.write(b)" where b is made of all "pending bytes". write() result 
is ignored: partial write is silently ignored.

== Python implementation ==

_pyio.TextIOWrapper.write() simply calls: "self.buffer.write(b)". It ignores 
partial write silently.

----------
nosy: +pitrou
title: Output of print() might get truncated in unbuffered mode -> 
io.TextIOWrapper ignores silently partial write if buffer is unbuffered

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

Reply via email to