From a2670565d8f5c502388378aba1fe73023fd8c8d4 Mon Sep 17 00:00:00 2001 From: Alexey Izbyshev Date: Sat, 20 Oct 2018 03:22:31 +0300 Subject: bpo-32236: open() emits RuntimeWarning if buffering=1 for binary mode (GH-4842) If buffering=1 is specified for open() in binary mode, it is silently treated as buffering=-1 (i.e., the default buffer size). Coupled with the fact that line buffering is always supported in Python 2, such behavior caused several issues (e.g., bpo-10344, bpo-21332). Warn that line buffering is not supported if open() is called with binary mode and buffering=1. --- Lib/subprocess.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'Lib/subprocess.py') diff --git a/Lib/subprocess.py b/Lib/subprocess.py index c827113a93..5db6f0cc24 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -743,12 +743,21 @@ class Popen(object): self._closed_child_pipe_fds = False + if self.text_mode: + if bufsize == 1: + line_buffering = True + # Use the default buffer size for the underlying binary streams + # since they don't support line buffering. + bufsize = -1 + else: + line_buffering = False + try: if p2cwrite != -1: self.stdin = io.open(p2cwrite, 'wb', bufsize) if self.text_mode: self.stdin = io.TextIOWrapper(self.stdin, write_through=True, - line_buffering=(bufsize == 1), + line_buffering=line_buffering, encoding=encoding, errors=errors) if c2pread != -1: self.stdout = io.open(c2pread, 'rb', bufsize) -- cgit v1.2.1