Port r54805 from python25-maint branch:
Port r54805 from python25-maint branch:

Add code to read from master_fd in the parent, breaking when we get an OSError
(EIO can occur on Linux) or there's no more data to read.  Without this,
test_pty.py can hang on the waitpid() because the child is blocking on the
stdout write.  This will definitely happen on Mac OS X and could potentially
happen on other platforms.  See the comment for details.

sk-/python2.7-type-annotator,sk-/python2.7-type-annotator,sk-/python2.7-type-annotator