title: Calling python script with subprocess.Popen and flushing the data
body: <p>Ok so i've seen dozen of threads like that , but none of them gives a complete answer and everything i tried so far foes not work for me.</p>
  
  <p><strong>1) Script that constantly outputs some data and flusheshs it:</strong></p>
  
  <pre><code>import time
  import sys
  
  if __name__ == '__main__':
      for i in range(5):
          print i,
          sys.stdout.flush()
          time.sleep(1)
  </code></pre>
  
  <p><strong>2) Script that calls first script with Popen and should be printing numbers one by one but for some reason does not, and prints them alltogether at once :</strong></p>
  
  <pre><code>import sys
  import subprocess
  
  if __name__ == '__main__':
      process = subprocess.Popen(['python', 'flush.py'], stdout = subprocess.PIPE )
      for line in iter(process.stdout.readline, ''):
          print line,
          sys.stdout.flush()
  </code></pre>
  
  <p>First thing i am a little bit confused is  in the <strong>first</strong> script is that if you remove the flush it returns output in one line alltogether O_O... I am pretty sure it is because of time.sleep but still kind of expected it return like a standart output constantly returning values 0,1,2,3,4  but not all together, ofcourse flush resolves it , but just strange, at least for me ...</p>
  
  <p><strong>The main problem:</strong> 
  Is that second script does not return number one by one , but returns all in one output at once..... What i need is to see numbers popping one by one...  </p>
  
  <p>I read somewhere that it does not return EOF which Popen waits to close the pipe , thats why it runs like to the end ..... </p>
  
  <p>So what do i do or try next ?  <em>Thanks in advance.</em></p>