Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98180
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | George Trojan <george.trojan@noaa.gov> |
| Newsgroups | comp.lang.python |
| Subject | Re: Unbuffered stderr in Python 3 |
| Date | Tue, 03 Nov 2015 18:03:51 +0000 |
| Lines | 58 |
| Message-ID | <mailman.41.1446573837.8789.python-list@python.org> (permalink) |
| References | <mailman.30.1446570002.25765.python-list@python.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de rjWXftQwkrmv/+3Cf8clTAqBYYQoTrboO9T8IYngFUDQ== |
| Return-Path | <george.trojan@noaa.gov> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.05; 'sys': 0.05; 'false.': 0.07; 'lost.': 0.09; 'received:140': 0.09; 'stderr': 0.09; 'streams.': 0.09; 'sys.stderr': 0.09; 'python': 0.10; 'buffering': 0.16; 'buffering,': 0.16; 'flushed': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'typing': 0.18; '>': 0.18; '2015': 0.20; '(the': 0.22; 'environments': 0.22; 'appears': 0.23; 'errors': 0.23; 'import': 0.24; '(most': 0.24; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'header:User-Agent:1': 0.26; 'skip:i 40': 0.27; "skip:' 10": 0.28; 'cat': 0.29; 'probably': 0.31; 'related': 0.32; 'skip:. 10': 0.32; 'usually': 0.33; "d'aprano": 0.33; 'steven': 0.33; "skip:' 20": 0.34; 'received:google.com': 0.35; 'false': 0.35; 'nov': 0.35; 'unicode': 0.35; 'skip:p 30': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'email addr:python.org': 0.36; 'to:addr :python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'turn': 0.37; 'received:209': 0.38; 'received:209.85.220': 0.38; 'does': 0.39; 'application': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'charset:windows-1252': 0.62; 'more': 0.63; 'importantly,': 0.66; 'here': 0.66; 'results': 0.66; 'or:': 0.84; 'killed': 0.91; 'email name:python-list-request': 0.93 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=noaa_gov.20150623.gappssmtp.com; s=20150623; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; bh=/4eMvDC1RraEi/oH2wdKJ9+uwJ+Irg9pjKAWfWepKlo=; b=2HnMHi2W8pESny/U5G7hy7BeVh44sKhc2oyZQwGi7UEJlsp+vxsUX99QS+xESpFhg0 MPBw0vZ6eiZTECDdxIHfs/aMZzjblG4huhaNrDjhowwdh4kI6Mk32nkEEEzlRsZqUYYP hWj8+l9zIG+ecuIvPGocFfrlp+HEdM0x7CdOQdu23GU5WEfERrhNGx/h7AYQiH0lsOIY HEk2AAQ0TbDsnJ5ZN0Oc6a6W2WEVQ1Wq/2pU4rKoPL3g7ZF+dovy4z26J0vIw4PRP6l8 IMFiIzCMbld8cjWsz2jepWkaMHzIJ0dTUBVWXppIuttYuDsoOM0/LRZ0R2c8YF11ma2y l9YQ== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type; bh=/4eMvDC1RraEi/oH2wdKJ9+uwJ+Irg9pjKAWfWepKlo=; b=TdL7TB24ZNcnIgpMW3mer3c9JkHs4gN3xaf19urf2noB/hHGCJ1vCyi/syBPavjuPr O06ZMq7Eyvy8ulYxvwHzA0Nmj26JQ6wMdQmAZ0sd96Di3hNQQ+XRlU1Mba3CyJpRZ2F1 9Es+kyRBLD0LimXNCYSB379VW6DQ2w7aCA+uwindAIlFoA2YfBPURXgJiN9tv8EUlFe/ FAgBu4M9BHcXQk+jG1/d/1WPRs3xlv5Ay/cEMMXs24PeCeV3Zs+VOFiWJK9a3K0j9AtQ n0aBHKXpSYZLarIb75KXAZ4JU6oINRZvE+H9RdEdkYdr/Y5B1qUlaB6IxMevqHjMYOyJ TCGw== |
| X-Gm-Message-State | ALoCoQketQ003K010z2GAlpEe+o12m/Mmw6a2r/owGpAP9XnS3dlnCdW/ok/ENmeLQjt2c2ADBWs |
| X-Received | by 10.68.65.42 with SMTP id u10mr35042256pbs.8.1446573833453; Tue, 03 Nov 2015 10:03:53 -0800 (PST) |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 |
| In-Reply-To | <mailman.30.1446570002.25765.python-list@python.org> |
| X-Content-Filtered-By | Mailman/MimeDel 2.1.20+ |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:98180 |
Show key headers only | View raw
On 11/03/2015 05:00 PM, python-list-request@python.org wrote:
> On Mon, 02 Nov 2015 18:52:55 +1100, Steven D'Aprano wrote:
>
>> In Python 2, stderr is unbuffered.
>>
>> In most other environments (the shell, C...) stderr is unbuffered.
>>
>> It is usually considered a bad, bad thing for stderr to be buffered. What
>> happens if your application is killed before the buffer fills up? The
>> errors in the buffer will be lost.
>>
>> So how come Python 3 has line buffered stderr? And more importantly, how
>> can I turn buffering off?
> It's probably related to the fact that std{in,out,err} are Unicode
> streams.
>
> > type(sys.stderr)
> <class '_io.TextIOWrapper'>
> > type(sys.stderr.buffer)
> <class '_io.BufferedWriter'>
> > type(sys.stderr.buffer.raw)
> <class '_io.FileIO'>
>
> It appears that you can turn it off with:
>
> sys.stderr = io.TextIOWrapper(sys.stderr.buffer.raw)
> or:
> sys.stderr = io.TextIOWrapper(sys.stderr.detach().detach())
>
> This results in a sys.stderr which appears to work and whose
> .line_buffering property is False.
>
>
This does set line buffering, but does not change the behaviour:
(devenv-3.4.1) dilbert@gtrojan> cat x.py
import sys
import time
if sys.version>'3':
import io
sys.stderr = io.TextIOWrapper(sys.stderr.detach().detach())
#sys.stderr = io.TextIOWrapper(sys.stderr.buffer.raw)
print(sys.stderr.line_buffering)
sys.stderr.write('a')
time.sleep(10)
This is python2.7.5. a is printed before ^C.
(devenv-3.4.1) dilbert@gtrojan> /bin/python x.py
a^CTraceback (most recent call last):
Here buffer is flushed on close, after typing ^C.
(devenv-3.4.1) dilbert@gtrojan> python x.py
False
^CaTraceback (most recent call last):
George
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Unbuffered stderr in Python 3 George Trojan <george.trojan@noaa.gov> - 2015-11-03 18:03 +0000
csiph-web