Fixing IPython Pipe Handling
SIGPIPE gets sent to a process when it tries to write to a pipe that is not read by another process. The default action for a process under these circumstances is to terminate.
Imagine a process yielding a huge amount of text, piped to head to print the first ten lines. With SIGPIPE ignored, the process will continue after head has stopped reading. Usually, this will only affect runtime – however, if the original process outputs an endless data stream, the shell will hang.
To check whether your shell ignores SIGPIPE, try the following command: yes | tee | head. It should print 10 lines with a single y each, then terminate. If the shell hangs, printing a message similar to tee: standard output: Broken pipe, SIGPIPE is ignored.
TL;DR: In IPython, proper SIGPIPE handling can be restored using the signal module: