As in pty.spawn, once started, the parent process will be hanged, even if the child process is already dead (or a zombie), and must wait for a KeyboardInterrupt or else to terminate the whole process. Thus, I propose to revise `_copy` function, where the parent process hung, to check if the child process is dead periodically and if so, terminate the whole process then return as shown in the patch file.
Is this to get “spawn” working on a non-Linux platform like a recent Free BSD, OS X, or Solaris? If so, see Issue 26228. If not, you might have to explain your use case better. Polling for the child exiting is going to race with handling the child’s output, and if there are other processes writing to the terminal after the child exits this will change the behaviour.