import os
import tty
import pty
program = 'python'
argv = ['python', 'foo.py']
pid, master_fd = pty.fork()
if pid == pty.CHILD:
    os.execlp(program, *argv)
Detecting when a child process is waiting for input