Python's pty.spawn() demystified

When I saw pty.spawn() for the first time, I thought "ok so it starts a new process in a new PTY. Easy." The implementation, however, was far from simple. For example in this simple gist : $ python3 py_pty_simple.py [PARENT] Spawning child in PTY... [CHILD] Running in PTY, press Ctrl+C... ^C [CHILD] Caught SIGINT, exiting... [PARENT] pty.spawn() returned, press Ctrl+C... ^C [PARENT] Caught SIGINT,…