Unbuffered stderr in Python 3

Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de
Wed Nov 4 06:49:49 EST 2015


On 04.11.2015 11:43, Wolfgang Maier wrote:
> On 04.11.2015 11:24, Steven D'Aprano wrote:
>> On Wed, 4 Nov 2015 07:19 pm, Wolfgang Maier wrote:
>>
>>> On 04.11.2015 04:18, Steven D'Aprano wrote:
>>>>
>>>> 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 :-)
>>
>
> I see :), but seriously, what I meant was: is it going to the console
> directly or is your code base redirecting sys.stderr to another buffered
> object first?
>

Standard I/O streams are line-buffered only if interactive (i.e., 
connected to a console), but block-buffered otherwise.
What does sys.stderr.isatty() return?





More information about the Python-list mailing list