def set_inheritable(fd, inheritable):
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
if inheritable:
flags &= ~fcntl.FD_CLOEXEC
else:
flags |= fcntl.FD_CLOEXEC
fcntl.fcntl(fd, fcntl.F_SETFD, flags)