Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ian Kelly Newsgroups: comp.lang.python Subject: Re: Other difference with Perl: Python scripts in a pipe Date: Thu, 10 Mar 2016 15:16:04 -0700 Lines: 44 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de yNsVL+urZNj+uECSdTVlcw8I6s+Svc4ZVY/iNrkRbeJQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'broken': 0.03; 'subject:Python': 0.05; 'sys': 0.05; 'ioerror:': 0.09; 'sys.stderr': 0.09; 'python': 0.10; 'thu,': 0.15; '2016': 0.16; 'cache:': 0.16; 'experiments': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'swallow': 0.16; 'wrote:': 0.16; "shouldn't": 0.18; 'pipe': 0.22; 'suppose': 0.22; 'import': 0.24; '(most': 0.24; 'header:In-Reply-To:1': 0.24; 'message- id:@mail.gmail.com': 0.27; 'cat': 0.29; 'command-line': 0.29; "i'm": 0.30; 'probably': 0.31; 'changed': 0.33; 'traceback': 0.33; 'file': 0.34; 'received:google.com': 0.35; 'but': 0.36; 'should': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'missing': 0.37; 'received:209.85.213': 0.37; 'seem': 0.37; 'received:209': 0.38; 'sure': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'behavior': 0.61; 'close': 0.61; '2000': 0.63; 'mar': 0.65; 'worth': 0.67; 'otten': 0.84; 'to:name:python': 0.84; 'hassle': 0.91; 'interesting,': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=E/RCrzebFqQ+aKQAXgnvSinxmdOAot12ePfyUl2F/3I=; b=D6p4EQ7l6XcW+puMY0tGfKbKXPOEH3u4dx2V0XI2cHu73iXqSRtN3bTTN60/Ws/acN pioljkZBRzSIEYA0ef509dVKswUgqapUcn6wy8hcBYF2Gx1Pi+7yPOcRvC0Ue71L4qLM 83ss4D1C/bhNuM1LQj0NbFIUPCTNPCfPbp7aJ1eN+0RWzFFOC76z33xiQkeeXvjSriMW EQGp1yeh4OktHm7ZG7Tv08sSnQOOOLz5rhWzdZKYfpMZCpaJ2Q1IgjGgxbxBauo8nVjB RXk9cRSmCevLK2YT/kGdcQlf0VmmCuJ5VJFNzZGmdh06VTzFM5fa3JUNqQMlWQMdVH8K bbUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=E/RCrzebFqQ+aKQAXgnvSinxmdOAot12ePfyUl2F/3I=; b=gXgMsn2paicG+ahDSl5bW6Pjev7G+3YvF8LsRW4uuo5bG+Fxbo8C8i0FstiP/SthhO H1oIZlHeFEaJGhbmHUKfbTk9CANCMNRvSBm+8uOZYE1wsQhFKSH3i1+/XUqscIr1ntAe tv8i5ODm/Y/ITqOfUDXMZSQ7x4WbQ9GlT1TBNPu/D55QjbUKU9BsVQ542uwy1H7dezXA exZmQdWiskCgVNgiho3UMH2Q0XEj78bvm2V8JPf5d/rcGz0XkwM9a/X0kO8OrWHomkNY tGV5AUR/RL9/pfJdoFuSL7CaWnzjZoOM3jVS53OQFv+WFT6m0MTonjL5lZpk4eu8qqNJ IlAA== X-Gm-Message-State: AD7BkJJO9KkmQmOiC+W2wrLAgL3OzW7sP5GlJur2EWcW629jAXha/SPYcvJrHw3nldJ8LnHFpSPXJ9pIHhg6uQ== X-Received: by 10.50.131.201 with SMTP id oo9mr364657igb.68.1457648203652; Thu, 10 Mar 2016 14:16:43 -0800 (PST) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:104558 On Thu, Mar 10, 2016 at 3:09 PM, Peter Otten <__peter__@web.de> wrote: > I suppose you need to fill the OS-level cache: > > $ cat somescript.py > import sys > > for i in range(int(sys.argv[1])): > sys.stdout.write('line %d\n' % i) > $ python somescript.py 20 | head -n5 > line 0 > line 1 > line 2 > line 3 > line 4 > $ python somescript.py 200 | head -n5 > line 0 > line 1 > line 2 > line 3 > line 4 > $ python somescript.py 2000 | head -n5 > line 0 > line 1 > line 2 > line 3 > line 4 > Traceback (most recent call last): > File "somescript.py", line 4, in > sys.stdout.write('line %d\n' % i) > IOError: [Errno 32] Broken pipe > > During my experiments I even got > > close failed in file object destructor: > sys.excepthook is missing > lost sys.stderr > > occasionally. Interesting, both of these are probably worth bringing up as issues on the bugs.python.org tracker. I'm not sure that the behavior should be changed (if we get an error, we shouldn't just swallow it) but it does seem like a significant hassle for writing command-line text-processing tools.