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.
1) Script that constantly outputs some data and flusheshs it:
import time
import sys
if __name__ == '__main__':
for i in range(5):
print i,
sys.stdout.flush()
time.sleep(1)
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 :
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()
First thing i am a little bit confused is in the first 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 ...
The main problem: 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...
I read somewhere that it does not return EOF which Popen waits to close the pipe , thats why it runs like to the end .....
So what do i do or try next ? Thanks in advance.