I have a Python3 script that writes its output to stdout, but it complains when I pipe that output into head or tail. Note in the sample output below that it sort of works,
./script.py '../Testdata/*indels.ss' -m 5 | awk 'NR >= 3 {exit} 1'
would show the same behavior as head -2.
head -2
You can turn set the SIGPIPE handler to one which quietly kills your program instead:
SIGPIPE
import signal signal.signal(signal.SIGPIPE, signal.SIG_DFL)