Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
pip list |head raises BrokenPipeError #4170
What I've run:
Output, for each package:
This behavior only appears with enough output (in my case, at least 11 lines).
yields the same logging error:
Note how it successfully work for the 10 first lines.
To quote from http://www.unixguide.net/unix/bash/E2.shtml
As far as I can see, this also closes the pipe's stdout, so I'm not sure how to handle this.
I'm not very educated on this topic, and I'm not clear on who you're asking to close it. My goal was to report it as a usability issue I was experiencing when using pip. Someone else marked it a 'bug'.
Isn't it pip's responsibility to handle the EPIPE/SIGPIPE gracefully? Or perhaps it's some underlying library's responsibility?
Do we at least agree that I should be seeing the first 10 lines of output, rather than a stack trace?
This was referenced
Mar 25, 2017
As can bee seen by the stack-trace, this annoyance is caused by standard python's logging-handlers that are not guarding against
It maybe worthy for
# Monkeypatch logging to behave when piped. old_flush = logging.StreamHandler.flush def flush(self): try: old_flush(self) except BrokenPipeError: pass # is our stderr piped in `head` or `tail`? logging.StreamHandler.flush = flush
I can provide a patch if you agree (and decide which method to apply).
referenced this issue
Aug 21, 2018
Hmm, overriding flush doesn't seem quite like the right approach to me here. One concern I'd have is that swallowing
A similar issue (still open) was discussed on the CPython tracker here: https://bugs.python.org/issue11380
I can post a patch in a short bit showing what I mean more specifically. It seems simpler and doesn't involve modifying any vendored libraries.