I was experimenting with subprocess.Popen with the following script:
$ cat Popen_ex.py
import sys, subprocess
po = subprocess.Popen([sys.executable, 'hello.py'],
stdout=subprocess.PIPE,
bufsize=0)
for line in po.stdout:
print line,
where hello.py is the following script:
$ cat hello.py
import time
time.sleep(1)
print 'hello'
time.sleep(1)
print 'world'
time.sleep(1)
print '*END*'
time.sleep(1)
It turns out that Popen collects all the output and write everything
together
after 4 seconds, where I would like to print a line every seconds.
How can I get that in a simple way? A Unix-only solution would be fine,
too.
Michele Simionato