Using python Popen to read the last line
问题 I have a simple python program: test.py: import time for i in range(100000): print i time.sleep(0.5) I want to use another program that executes the above one in order to read the last line output while the above program is counting. import subprocess process = subprocess.Popen("test",stdout=PIPE) sleep(20) # sleeps an arbitrary time print stdout.readlines()[-1] The problem is that process.stdout.readlines() waits until test.py finishes execution. Is there any way to read the last line that