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,
I'll cite from here:
If a sequence of commands appears in a pipeline, and one of the
reading commands finishes before the writer has finished, the
writer receives a SIGPIPE signal.
That's what head does. Your script hasn't finished writing, but head is already done, so stdout is closed, hence the exception.