On Wed, 27 Aug 2014 08:29:20 +0300, Marko Rauhamaa wrote:
> Steven D'Aprano <[email protected]>:
>
>> When I pipe one to the other, I expect each line to be printed as they
>> arrive, but instead they all queue up and happen at once:
>
> Try flushing after each print.
Doesn't help.
Here is an update that may make the problem more clear:
steve@runes:~$ cat out.py
import time
import sys
print "Time of output:", time.ctime()
sys.stdout.flush()
time.sleep(10)
print "Time of output:", time.ctime()
sys.stdout.flush()
time.sleep(10)
print "Time of output:", time.ctime()
steve@runes:~$ cat slurp.py
import sys
import time
for line in sys.stdin:
print "Time of input:", time.ctime(), line
sys.stdin.flush()
sys.stdout.flush()
And the results:
steve@runes:~$ python out.py | python slurp.py
Time of input: Wed Aug 27 16:35:48 2014 Time of output: Wed Aug 27 16:35:28 2014
Time of input: Wed Aug 27 16:35:48 2014 Time of output: Wed Aug 27 16:35:38 2014
Time of input: Wed Aug 27 16:35:48 2014 Time of output: Wed Aug 27 16:35:48 2014
--
Steven
--
https://mail.python.org/mailman/listinfo/python-list