When the pipeline prints the output using a python script with the grep command, the output from the script is apparently only passed to the next command after the entire script has completed.
For example, in the test_grep.py script, as shown below:
#!/usr/bin/env python from time import sleep print "message1" sleep(5) print "message2" sleep(5) print "message3"
when called with ./test_grep.py | grep message ./test_grep.py | grep message will not appear for 10 seconds, and at this time all three lines will appear.
Compare this with the test_grep.sh script:
#!/usr/bin/env bash echo "message1" sleep 5 echo "message2" sleep 5 echo "message3"
./test_grep.sh | grep message ./test_grep.sh | grep message will immediately output message1 , and then after 5 seconds at intervals of message2 and message3 .
I expect this to happen only after the python interpreter completes execution, this is the output available for the next command. Is there any way to change this behavior?
source share