Flush stdin

Empty Account emptya45 at gmail.com
Fri Oct 17 07:38:54 EDT 2014


Hi,

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.

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')


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

Many Thanks

Aidy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141017/0311b2be/attachment.html>


More information about the Python-list mailing list