'Create pipes for parent to child stdin/stdout/stderr
communications.  Open fd in non-blocking mode so we can read them
in the mainloop without blocking.  If stderr is False, don\'t
create a pipe for stderr.'

def make_pipes(self, stderr=True):

    pipes = {'child_stdin': None, 'stdin': None, 'stdout': None, 'child_stdout': None, 'stderr': None, 'child_stderr': None}
    try:
        (stdin, child_stdin) = os.pipe()
        (pipes['child_stdin'], pipes['stdin']) = (stdin, child_stdin)
        (stdout, child_stdout) = os.pipe()
        (pipes['stdout'], pipes['child_stdout']) = (stdout, child_stdout)
        if stderr:
            (stderr, child_stderr) = os.pipe()
            (pipes['stderr'], pipes['child_stderr']) = (stderr, child_stderr)
        for fd in (pipes['stdout'], pipes['stderr'], pipes['stdin']):
            if (fd is not None):
                flags = (fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NDELAY)
                fcntl.fcntl(fd, fcntl.F_SETFL, flags)
        return pipes
    except OSError:
        for fd in pipes.values():
            if (fd is not None):
                self.close_fd(fd)
        raise
