When a naive engineer (me a month ago) sees pty.spawn() for the first time, they might think “ok so it starts a new process in a new PTY. Easy.” The implementation, however, is far from simple. This post will go over how it works under the hood. What is PTY? Pseudo-terminal (PTY) is a virtualization of the legacy teletype (TTY) hardware. It consists of a pair of character devices: leader & follower (or master & slave). The pair acts as a bidirectional channel. All writes to the device fil...