def SetNonblockFlag(fd, enable):
  flags = fcntl.fcntl(fd, fcntl.F_GETFL)

  if enable:
    flags |= os.O_NONBLOCK
  else:
    flags &= ~os.O_NONBLOCK

  fcntl.fcntl(fd, fcntl.F_SETFL, flags)
Sets or unsets the O_NONBLOCK flag on on a file descriptor.
dataset/ETHPy150Open ganeti/ganeti/lib/utils/wrapper.py/SetNonblockFlag