-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
Python io implementation doesn't flush with write_through=True unlike C implementation #65595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
related: msg217596 (bufsize=1 is broken if subprocess module uses Python io) TextIOWrapper.write behavior: _pyio.py 1: if self._line_buffering and (haslf or "\r" in s):
self.flush() textio.c 2:
C implementation calls flush() if write_through=True, Python implementation doesn't. |
Thanks for the report, Akira. Feel free to submit a patch! (with a test) |
I've uploaded the patch that makes C implementation behave according Issue bpo-21332 is a dependency for this issue: subprocess' test_universal_newlines needs to be updated to work with Python version. For Reference issue bpo-12591 introduces 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 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 python/cpython#65531 http://hg.python.org/cpython/rev/9ce8fa0a0899/ - introduce io.TextIOWrapper in subprocess |
The patch looks basically fine. I will make a few tweaks to the comments in the test case. |
Actually, with the patch, the universal_newlines tests in test_subprocess hang (quite logically, since they lack a flush()). I will fix them as well. |
New changeset 39f2a78f4357 by Antoine Pitrou in branch '3.4': New changeset 37d0c41ed8ad by Antoine Pitrou in branch 'default': |
Thank you for the patch! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: