title: Python: select() doesn't signal all input from pipe
body: <p>I am trying to load an external command line program with Python and communicate with it via pipes. The progam takes text input via stdin and produces text output in lines to stdout. Communication should be asynchronous using select().</p>
  
  <p>The problem is, that not all output of the program is signalled in select(). Usually the last one or two lines are not signalled. If select() returns with a timeout and I am trying to read from the pipe anyway readline() returns immediately with the line sent from the program. See code below.</p>
  
  <p>The program doesn't buffer the output and sends all output in text lines. Connecting to the program via pipes in many other languages and environments has worked fine so far.</p>
  
  <p>I have tried Python 3.1 and 3.2 on Mac OSX 10.6.</p>
  
  <pre><code>import subprocess
  import select
  
  engine = subprocess.Popen("Engine", bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
  engine.stdin.write(b"go\n")
  engine.stdin.flush()
  
  while True:
      inputready,outputready,exceptready = select.select( [engine.stdout.fileno()] , [], [], 10.0)
  
      if (inputready, outputready, exceptready) == ([], [], []):
          print("trying to read from engine anyway...")
          line = engine.stdout.readline()
          print(line)
  
       for s in inputready:
          line = engine.stdout.readline()
          print(line)
  </code></pre>