bpo-30404: The -u option now makes the stdout and stderr streams tota… · python/cpython@77732be (original) (raw)

4 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -303,13 +303,13 @@ Miscellaneous options
303 303
304 304 .. cmdoption:: -u
305 305
306 - Force the binary layer of the stdout and stderr streams (which is
307 - available as their ``buffer`` attribute) to be unbuffered. The text I/O
308 - layer will still be line-buffered if writing to the console, or
309 - block-buffered if redirected to a non-interactive file.
306 + Force the stdout and stderr streams to be unbuffered.
310 307
311 308 See also :envvar:`PYTHONUNBUFFERED`.
312 309
310 + .. versionchanged:: 3.7
311 + The text layer of the stdout and stderr streams now is unbuffered.
312 +
313 313
314 314 .. cmdoption:: -v
315 315
Original file line number Diff line number Diff line change
@@ -221,13 +221,12 @@ def test_unbuffered_output(self):
221 221 rc, out, err = assert_python_ok('-u', '-c', code)
222 222 data = err if stream == 'stderr' else out
223 223 self.assertEqual(data, b'x', "binary %s not unbuffered" % stream)
224 -# Text is line-buffered
225 -code = ("import os, sys; sys.%s.write('x\\n'); os._exit(0)"
224 +# Text is unbuffered
225 +code = ("import os, sys; sys.%s.write('x'); os._exit(0)"
226 226 % stream)
227 227 rc, out, err = assert_python_ok('-u', '-c', code)
228 228 data = err if stream == 'stderr' else out
229 -self.assertEqual(data.strip(), b'x',
230 -"text %s not line-buffered" % stream)
229 +self.assertEqual(data, b'x', "text %s not unbuffered" % stream)
231 230
232 231 def test_unbuffered_input(self):
233 232 # sys.stdin still works with '-u'
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1 +The -u option now makes the stdout and stderr streams unbuffered rather than
2 +line-buffered.
Original file line number Diff line number Diff line change
@@ -1498,7 +1498,7 @@ create_stdio(PyObject* io,
1498 1498 PyObject *buf = NULL, *stream = NULL, *text = NULL, *raw = NULL, *res;
1499 1499 const char* mode;
1500 1500 const char* newline;
1501 -PyObject *line_buffering;
1501 +PyObject *line_buffering, *write_through;
1502 1502 int buffering, isatty;
1503 1503 _Py_IDENTIFIER(open);
1504 1504 _Py_IDENTIFIER(isatty);
@@ -1555,7 +1555,11 @@ create_stdio(PyObject* io,
1555 1555 Py_DECREF(res);
1556 1556 if (isatty == -1)
1557 1557 goto error;
1558 -if (isatty |
1558 +if (Py_UnbufferedStdioFlag)
1559 +write_through = Py_True;
1560 +else
1561 +write_through = Py_False;
1562 +if (isatty && !Py_UnbufferedStdioFlag)
1559 1563 line_buffering = Py_True;
1560 1564 else
1561 1565 line_buffering = Py_False;
@@ -1574,9 +1578,9 @@ create_stdio(PyObject* io,
1574 1578 newline = "\n";
1575 1579 #endif
1576 1580
1577 -stream = _PyObject_CallMethodId(io, &PyId_TextIOWrapper, "OsssO",
1581 +stream = _PyObject_CallMethodId(io, &PyId_TextIOWrapper, "OsssOO",
1578 1582 buf, encoding, errors,
1579 -newline, line_buffering);
1583 +newline, line_buffering, write_through);
1580 1584 Py_CLEAR(buf);
1581 1585 if (stream == NULL)
1582 1586 goto error;