cleo
cleo copied to clipboard
cleo does not handle SIGPIPE / errno.EPIPE
Discovered this trying to work around sdispater/poetry#106 doing something along the lines of poetry show -v | head -n1 | ...
Using the GreetCommand given in the README:
% python app.py | head
Console Tool
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
[BrokenPipeError]
[Errno 32] Broken pipe
list [--raw] [--format FORMAT] [--] [<namespace>]
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>
BrokenPipeError: [Errno 32] Broken pipe
% echo $?
0
Edit: I didn't see that poetry uses cleo 0.6.8, and the current version is 0.7.2, so I'm not sure yet if the problem still exists in the current version.
This is the cause of https://github.com/sdispater/poetry/issues/839. In that issue I reference a StackOverflow post with a solution. Here is the short version:
# in cleo/outputs/stream_output.py
from signal import signal, SIGPIPE, SIG_DFL
signal(SIGPIPE, SIG_DFL)
The process writing to the pipe will now be terminated when it receives SIGPIPE (i.e. when the other end of the pipe is closed prematurely), rather than raising a BrokenPipeError.
I would be more than willing to put together a PR for this since it's very little code.
Facing the same issue while doing the same thing. @zmitchell did you ever figure out a solution that doesn't require editing the source?
EDIT: Found the env command for poetry, which gives the virtualenv path - poetry env info -p. This solves my problem for now, but it would still be nice to see this issue resolved.