Unbuffered stderr in Python 3

Steven D'Aprano steve at pearwood.info
Wed Nov 4 05:24:29 EST 2015


On Wed, 4 Nov 2015 07:19 pm, Wolfgang Maier wrote:

> On 04.11.2015 04:18, Steven D'Aprano wrote:
>> On Wednesday 04 November 2015 09:25, Terry Reedy wrote:
>>
>>> On 11/3/2015 10:42 AM, Chris Angelico wrote:
>>>> On Wed, Nov 4, 2015 at 2:00 AM, Random832 <random832 at fastmail.com>
>>>> wrote:
>>>>> Nobody <nobody at nowhere.invalid> writes:
>>>>>
>>>>>> It's probably related to the fact that std{in,out,err} are Unicode
>>>>>> streams.
>>>>>
>>>>> There's no fundamental reason a Unicode stream should have to be line
>>>>> buffered. If it's "related", it's only in that an oversight was made
>>>>> in the course of making that change.
>>>
>>> The current behavior is not an 'oversight'.  I was considered, decided,
>>> and revisited in https://bugs.python.org/issue13601.  Guido:
>>> "Line-buffering should be good enough since in practice errors messages
>>> are always terminated by a newline."  If not, print(part_line,
>>> file=sys.stderr, flush=True) works for the unusual case.
>>
>> This is one of the offending line from our code base:
>>
>> print('<4>Suspicious answer "{}"!'.format(answer), file=sys.stderr)
>>
>> So that ought to be terminated by a newline. And yet, the stderr output
>> doesn't show up until the program exits.
>>
> 
> For me, that prints immediately. Where is your output going? Console,
> file, ...?

Going to stderr, like the whole thread is about :-)


The output does eventually show up written to the console, but only after
Python exits.



-- 
Steven




More information about the Python-list mailing list