http://docs.python.org/library/pty.html says -
pty.fork()¶ Fork. Connect the child’s controlling terminal to a pseudo-terminal. Return value is
Thanks Joni.Here is what i understood.When pty.fork() is invoked. parent process is connected to ptmx master. parent will wait for input from keyboard or data from master.
child closes its stdin,stdout and stderr. And duplicates slaves stdin,stdout.stderr. now child executed a program (say bc).The program is waiting for input,when you type 1+1--its passed to master (remember both child and slave has some stdin,stdout,stderr) by child/slave. master computes its answer "2" and writes into stdout- since parent is waiting for data from master -it picks up "2" and writes into stdout.
I came this conclusion after going through few good old c programs on pseudo-terminal :) I don't think python's logic won't be different from them. HTH someone.