O_NONBLOCK是状态标志,而不是描述符标志。因此,请使用
F_SETFL来设置文件状态标志,而不是
F_SETFD用于设置文件描述符标志。
另外,请确保将整数文件描述符作为第一个参数传递给
fcntl.fcntl,而不是Python文件对象。因此使用
f = open("/tmp/out", "r")fd = f.fileno()fcntl.fcntl(fd, fcntl.F_SETFL, flag | os.O_NONBLOCK)
而不是
fd = open("/tmp/out", "r")...fcntl.fcntl(fd, fcntl.F_SETFD, flag | os.O_NONBLOCK)flag = fcntl.fcntl(fd, fcntl.F_GETFD)
import fcntlimport oswith open("/tmp/out", "r") as f: fd = f.fileno() flag = fcntl.fcntl(fd, fcntl.F_GETFL) fcntl.fcntl(fd, fcntl.F_SETFL, flag | os.O_NONBLOCK) flag = fcntl.fcntl(fd, fcntl.F_GETFL) if flag & os.O_NONBLOCK: print "O_NONBLOCK!!"
版画
O_NONBLOCK!!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)