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"
Does anybody know if select.select() works with regular files or just with sockets/pipes?
I've tried on Solaris, Linux and Mac OS X - it doesn't block on select.select() call.
It just explodes my brain, trying something like this with no luck
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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自文档:
这有帮助吗?
From the documentation:
Does that help?
select
也应该适用于文件,但我认为文件的 FD 将始终准备就绪。您还应该检查是否到达文件末尾。这是一个对我有用的例子:
select
should work for files also, but I think FD for files gonna be always ready.You should also check if you reached the end of the file. Here is an example which works for me: