【发布时间】:2015-05-11 16:03:47
【问题描述】:
我想以非阻塞模式读取文件。 所以我喜欢下面
import fcntl
import os
fd = open("./filename", "r")
flag = fcntl.fcntl(fd.fileno(), fcntl.F_GETFD)
fcntl.fcntl(fd, fcntl.F_SETFD, flag | os.O_NONBLOCK)
flag = fcntl.fcntl(fd, fcntl.F_GETFD)
if flag & os.O_NONBLOCK:
print "O_NONBLOCK!!"
但是flag的值仍然代表0。
为什么..?我觉得应该改成os.O_NONBLOCK
当然,如果我调用 fd.read(),它会在 read() 处被阻塞。
【问题讨论】:
标签: python python-2.7 nonblocking