对于Unix,您可以使用termios.tcflush
from termios import tcflush, TCIFLUSHimport time,sysa = raw_input("first input ")b = raw_input("second input ")time.sleep(5)tcflush(sys.stdin, TCIFLUSH)a = raw_input("third input ")b = raw_input("fourth input ")~$ python foo.py first input 1second input 23333third input 3fourth input 4termios.tcflush(fd,队列)
丢弃文件描述符fd上的排队数据。 队列选择器指定哪个队列:输入队列为TCIFLUSH,输出队列为TCOFLUSH,两个队列均为TCIOFLUSH。



