Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Nobody Newsgroups: comp.lang.python Subject: Re: Flush stdin Date: Sat, 18 Oct 2014 17:55:19 +0100 Organization: A noiseless patient Spider Lines: 27 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="152d4dee6f95183c956ee6fa63d7e69f"; logging-data="777"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ad2QD6Qp9RUCLPVrnUDqa" User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.) Cancel-Lock: sha1:7TnyL3hmKvYDoQ8ClK5jdjGfzEY= Xref: csiph.com comp.lang.python:79272 On Fri, 17 Oct 2014 12:38:54 +0100, Empty Account 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, You can't "flush" an input stream. > so I am using the termios module. > I am receiving this exception > termios.error: (25, 'Inappropriate ioctl for device') termios only works on terminals, not pipes. It's a safe bet that your problem is that "nc" isn't flushing its stdout after each line (this is the default behaviour for stdio streams which don't correspond to a terminal). Check whether "nc" has a flag to line-buffer its output. If it doesn't, the simplest solution is probably to write a Python script which creates a pseudo-tty (using the "pty" module) and executes "nc" with its stdout associated with the pty.