def spawn(argv, master_read=pty_read, stdin_read=pty_read):
    """Create a spawned process.
    Based on pty.spawn code."""
    # TODO(larsbutler): This type check won't work with python3
    # See http://packages.python.org/six/#six.string_types
    # for a possible solution.
    if isinstance(argv, (basestring)):
        argv = (argv,)
    pid, master_fd = pty.fork()
    if pid == pty.CHILD:
        os.execlp(argv[0], *argv)
    try:
        mode = tty.tcgetattr(pty.STDIN_FILENO)
        tty.setraw(pty.STDIN_FILENO)
        restore = 1
    except tty.error:    # This is the same as termios.error
        restore = 0
    # get pseudo-terminal window size
    buf = array.array('h', [0, 0, 0, 0])
    fcntl.ioctl(pty.STDOUT_FILENO, termios.TIOCGWINSZ, buf, True)
    # pass window size settings to forked one
    fcntl.ioctl(master_fd, termios.TIOCSWINSZ, buf)
    try:
        pty_copy(master_fd, master_read, stdin_read)
    except (__HOLE__, OSError):
        if restore:
            tty.tcsetattr(pty.STDIN_FILENO, tty.TCSAFLUSH, mode)

    os.close(master_fd)
dataset/ETHPy150Open zerovm/zerovm-cli/zvshlib/zvsh.py/spawn