Common set-up code for initializing a (pipe) file descriptor

def _setup_fd(fd):
    """Common set-up code for initializing a (pipe) file descriptor"""

    # Make the file nonblocking (but don't lose its previous flags)
    flags = fcntl.fcntl(fd, fcntl.F_GETFL)
    fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
    set_buf_size(fd)