title: Turn off buffering
body: <p>Where is the buffer in this following ... and how do I turn it off?</p>
  
  <p>I am writing out to stdout in a python program like so:</p>
  
  <pre><code>for line in sys.stdin:
      print line
  </code></pre>
  
  <p>There is some buffering going on here:</p>
  
  <pre><code>tail -f data.txt | grep -e APL | python -u Interpret.py
  </code></pre>
  
  <p>I tried the following to shake off possible buffering ... with no luck:</p>
  
  <ul>
  <li>as above using the -u flag with python invocation</li>
  <li>calling sys.stdout.flush() after each sys.stdout.write() call
  ... all of these create a buffered stream with python waiting something like a minute to print out the first few lines.</li>
  <li><p>used the following modified command:</p>
  
  <p>stdbuf -o0 tail -f data.txt | stdbuf -o0 -i0 grep -e APL | stdbuf -i0 -o0 python -u Interpret.py</p></li>
  </ul>
  
  <p>To benchmark my expectations, I tried:</p>
  
  <pre><code>tail -f data.txt | grep -e APL 
  </code></pre>
  
  <p>This produces a steady flow of lines ... it surely is not as buffered as the python command.</p>
  
  <p>So, how do I turn off buffering?
  ANSWER: It turns out there is buffering on both ends of the pipe.</p>