有没有人知道select.select()是否适用于普通文件或仅适用于套接字/管道?select.select()与常规文件
我在Solaris,Linux和Mac OS X上尝试过 - 它不会阻塞select.select()调用。
它只是爆炸我的大脑,试图像这样没有运气
import os
import select
fds = [ os.open("read.txt", os.O_RDONLY) ]
while True:
reads, _, _ = select.select(fds, [], [], 2.0)
if 0 < len(reads):
print "-> ",os.read(reads[0], 10)
else:
print "timeout"
这与python比底层操作系统有关。使用常规文件更好地阅读非阻塞io和异步io。 – 2011-01-31 18:26:57