[issue21396] Python io implementation doesn't flush with write_through=True unlike C implementation
akira
report at bugs.python.org
Thu May 1 12:27:33 CEST 2014
akira added the comment:
I've uploaded the patch that makes C implementation behave according
to the docs like Python implementation with the corresponding tests.
Issue #21332 is a dependency for this issue: subprocess' test_universal_newlines needs to be updated to work with Python version.
For Reference
-------------
issue #12591 introduces `write_through` to support subprocess' stdin
pipe in text mode with bufsize=0 i.e., TextIOWrapper.buffer is
unbuffered (raw) and Python and C implementation behave the same in
this particular case.
C implementation (pseudo-code)::
if self.write_through:
flush_text_buffer()
buffer.flush() # <-- undocumented
Python implementation::
if self.write_through:
pass # _pyio.TextIOWrapper.write() calls buffer.write() directly
behaves according to the current documentation [1]:
If *write_through* is ``True``, calls to :meth:`write` are guaranteed
not to be buffered: any data written on the :class:`TextIOWrapper`
object is immediately handled to its underlying binary *buffer*
[1]: hg.python.org/cpython/file/2a56d3896d50/Doc/library/io.rst
For reference, here's how subprocess.py uses write_through [2]::
self.stdin = io.open(pipe, 'wb', bufsize)
if universal_newlines=True:
self.stdin = io.TextIOWrapper(self.stdin,
write_through=True,
line_buffering=(bufsize == 1)) # <-- issue #21332
http://hg.python.org/cpython/rev/9ce8fa0a0899/ - introduce io.TextIOWrapper in subprocess
http://hg.python.org/cpython/rev/5cc536fbd7c1 - introduce write_through
[2]: http://hg.python.org/cpython/file/2a56d3896d50/Lib/subprocess.py#l849
----------
keywords: +patch
Added file: http://bugs.python.org/file35125/io-write_through-c-vs-python-issue21396.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21396>
_______________________________________
More information about the Python-bugs-list
mailing list