有沒有人知道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