采用
os.read(f.fileno(), 50)
代替。这不会等到已读取指定的字节数,而是在读取任何内容(最多指定的字节数)后返回。
万一您 没有 从该管道读取的内容,这不能解决您的问题。在这种情况下,您应该使用
select模块中的内容
select来 测试
是否有需要阅读的内容。
编辑:
使用以下命令测试空输入
select:
import selectr, w, e = select.select([ f ], [], [], 0)if f in r: print os.read(f.fileno(), 50)else: print "nothing available!" # or just ignore that case



