code: def forkexec_pty(argv, env=None, size=None):
      
      child_pid, child_fd = pty.fork()
      if child_pid == 0:
          os.closerange(3, MAXFD)
          environ = os.environ.copy()
          if env is not None:
              environ.update(env)
          os.execve(argv[0], argv, environ)
      if size is None:
          try:
              size = get_terminal_size(1)
          except Exception:
              size = (80, 24)
      set_terminal_size(child_fd, size)
      return child_pid, child_fd
docs: Fork a child process attached to a pty.