title: Force another program's standard output to be unbuffered using Python
body: <p>A python script is controlling an external application on Linux, passing in input via a pipe to the external applications stdin, and reading output via a pipe from the external applications stdout. </p>
  
  <p>The problem is that writes to pipes are buffered by block, and not by line, and therefore delays occur before the controlling script receives data output by, for example, printf in the external application.</p>
  
  <p>The external application cannot be altered to add explicit fflush(0) calls.</p>
  
  <p>How can the <a href="http://python.org/doc/2.3.5/lib/module-pty.html" rel="noreferrer">pty</a> module of the python standard library be used with the <a href="http://docs.python.org/library/subprocess.html" rel="noreferrer">subprocess</a> module to achieve this?</p>