Python Archivo de lectura sin bloque
Quiero leer un archivo con modo sin bloque. Así que me gustó a continuación
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!!"
Pero el valorflag
todavía representa 0. ¿Por qué ...? Creo que debería ser cambiado de acuerdo aos.O_NONBLOCK
Y, por supuesto, si llamo a fd.read (), se bloquea en read ().