Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79261

Re: Flush stdin

Date 2014-10-18 18:11 +1100
From Cameron Simpson <cs@zip.com.au>
Subject Re: Flush stdin
References <CABcP1UeH9ft0j++HbUpHDDWz4i=7eJrDU=kVXFN6LPHT3oNE6Q@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.14960.1413616320.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 17Oct2014 12:38, Empty Account <emptya45@gmail.com> wrote:
>I am using netcat to listen to a port and python to read stdin and print to
>the console.
>
>nc -l 2003 | python print_metrics.py
>
>sys.stdin.flush() doesn’t seem to flush stdin, so I am using the termios
>module. 

You're aware that a stdio flush and a termios flush operate on two totally 
unrelated buffers?

>while True: 
>   input = sys.stdin.readline()
>   # do some parsing 
>   …  
>   sys.stdout.write(parsed_data)
>   time.sleep(3)
>   termios.tcflush(sys.stdin, termios.TCIOFLUSH)
>
>I am receiving this exception
>termios.error: (25, 'Inappropriate ioctl for device')

That is because stdin is attached to the pipe from netcat. A pipe is not a 
terminal.

>I will be using this script on Unix based systems and I wondered what
>approach I could use 
>to flush stdin?

Like Chris, I think you need to explain why you even want to flush stdin.  
There's probably something better you can do.

Cheers,
Cameron Simpson <cs@zip.com.au>

I strongly suspect so.  Practically everyone on sci.physics has a theory that
is far superior to special relativity, general relativity, quantum mechanics
*and* the standard model.  Around here, it's only a small clique of arrogant
young members of the physics establishment who fail to recognize these
revolutionary theories.  I'd explain why, but I have to go finish designing
my faster-than-light vacuum energy perpetual motion telekinetic
aether-powered time machine.    - John Baez

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Flush stdin Cameron Simpson <cs@zip.com.au> - 2014-10-18 18:11 +1100

csiph-web