Path: csiph.com!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'output': 0.05; '21,': 0.07; 'suppose': 0.07; 'sys': 0.07; 'dan': 0.09; 'excluding': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '(there': 0.16; 'buffering,': 0.16; 'cc:name:python list': 0.16; 'descriptor': 0.16; 'localhost': 0.16; 'popping': 0.16; 'stdout': 0.16; 'tcp': 0.16; 'termination.': 0.16; 'test).': 0.16; 'thread,': 0.16; 'tty': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'written': 0.21; '(the': 0.22; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'versions': 0.24; 'cc:2**0': 0.24; 'second': 0.26; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'appear': 0.29; 'character': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '-0700,': 0.31; '>>>>': 0.31; 'yes.': 0.31; 'file': 0.32; 'probably': 0.32; "we're": 0.32; 'run': 0.32; 'another': 0.32; '(i.e.': 0.33; 'skip:# 10': 0.33; "can't": 0.35; 'problem.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'done': 0.36; "didn't": 0.36; 'should': 0.36; 'two': 0.37; 'pm,': 0.38; 'that,': 0.38; 'does': 0.39; 'sure': 0.39; 'even': 0.60; 'read': 0.60; 'eventually': 0.60; "you're": 0.61; 'further': 0.61; 'kind': 0.63; 'different': 0.65; 'here': 0.66; 'between': 0.67; 'nobody': 0.68; 'wish': 0.70; 'acts': 0.74; '9000': 0.84; 'to:addr:nobody': 0.96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=5fMf3/NZgGKdMaFI67YMS0FXUPDZg5iOg7YiVrJfnTI=; b=wIU9d7HslUjwTOMfzovarvbq1pIYREGJitXeRiRdnAVjiIyyxgBKFQMpB/BftAwt/1 A0zbKJjVxKqWk4+3aaghA7SSQPevathOdxyh+6D20X/9NR9NLIdtyhx7RH6lS3ddShCX 8/q8I99hA3lJGYQmvty/m+DtGLKOG/t0De1HkGdAGjpyiXfX0b0JV2TjeE0/M5DV03Pg TK334J/NoSZxW8k9VTeqAvmwFtqhncNlaDiYGs0Px5E6hmBRyuqNstGzYMVEBjuVcRPp ipkGhCSEmP/9xMN+qFOXoaBgRlzf9F+KbDpditZ2Mpbc+Lf6TFPWOKf5HON0dHswLPLX dRiA== MIME-Version: 1.0 X-Received: by 10.152.2.41 with SMTP id 9mr11162543lar.47.1413947494153; Tue, 21 Oct 2014 20:11:34 -0700 (PDT) In-Reply-To: References: Date: Tue, 21 Oct 2014 20:11:34 -0700 Subject: Re: Flush stdin From: Dan Stromberg To: Nobody Content-Type: text/plain; charset=UTF-8 Cc: Python List X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1413947502 news.xs4all.nl 2840 [2001:888:2000:d::a6]:42767 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79410 On Tue, Oct 21, 2014 at 7:49 PM, Nobody wrote: > On Sat, 18 Oct 2014 18:42:00 -0700, Dan Stromberg wrote: > >> On Sat, Oct 18, 2014 at 6:34 PM, Dan Stromberg wrote: >>>> Once the "nc" process actually write()s the data to its standard >>>> output (i.e. desriptor 1, not the "stdout" FILE*) >>> I'm not sure why you're excluding stdout, but even if nc is using >>> filedes 1 instead of FILE * stdout, isn't it kind of irrelevant? >> >> On further reflection, isn't it stdio that does the varied buffering, >> and filedes 1 that's always unbuffered? IOW, the OP might wish nc was >> using 1, but it probably can't be given what they're seeing. > > Yes. stdio does buffering. Writing to stdout stores data in a buffer; that > data should eventually be written to descriptor 1, although perhaps not > until immediately prior to termination. > > Which is probably the cause of the OP's problem. Huh. And here I thought I demonstrated elsewhere in this thread, that the buffering between nc and python didn't appear to be the problem. 'found it, here it is again: If I run the following in one tty: nc -l localhost 9000 | /tmp/z ...where /tmp/z has just: #!/usr/bin/python3 import sys for line in sys.stdin.buffer: print(line) And then run the following in another tty on the same computer: while read line; do echo $line; sleep 1; done < /etc/passwd | nc localhost 9000 ...then everything acts line buffered, or perhaps even character buffered (the two are pretty indistinguishable in this test). What I see is my /etc/passwd file popping out of the nc -l side, one line at a time, each line one second apart. I suppose this suggests that it's the client that's sending TCP data that is buffering. That, or we're using two different versions of netcat (there are at least two available).