Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BrokenPipeError when poetry show -v | head -n 1 #839

Closed
3 tasks done
nyanpasu64 opened this issue Jan 26, 2019 · 8 comments
Closed
3 tasks done

BrokenPipeError when poetry show -v | head -n 1 #839

nyanpasu64 opened this issue Jan 26, 2019 · 8 comments

Comments

@nyanpasu64
Copy link

  • I am on the latest Poetry version.

  • I have searched the issues of this repo and believe that this is not a duplicate.

  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

  • OS version and name: Ubuntu 18.04 x64, zsh

  • Poetry version: 0.12.11

  • Link of a Gist with the contents of your pyproject.toml file: probably irrelevant

Issue

It was suggested on the issue tracker, that to "find the virtualenv path", I run poetry show -v and look at the first line.

To automate that process, I tried executing poetry show -v | head -n 1 in zsh. However when head closes the pipe, Poetry instead raises BrokenPipeError.

https://gist.github.com/jimbo1qaz/014f6e831af944db235e77af61339b49 (poetry show -vvv, not -v)

Is this a reasonable use case? Is it possible to catch this error and stop writing to stdout (or terminate)?

(Note: on Windows, depending on buffer size, subprocess.Popen pipes may produce OSError instead. But this is not a Popen pipe, but a shell pipe.)

@zmitchell
Copy link

zmitchell commented Feb 9, 2019

Your traceback shows that the error lies within cleo. After searching for some context, it appears that pip faced a similar issue some time ago (see here). It looks like the BrokenPipeError does indeed come from head closing the pipe before poetry/cleo is done writing i.e. it closes the pipe after it's read the N lines in a call to head -n N. It looks like the pip crew just chose to print a more helpful error message in the end, so that could be a solution here.

@nyanpasu64
Copy link
Author

nyanpasu64 commented Feb 9, 2019

I feel that pipenv/poetry are not designed to handle non-web apps well: both make it very difficult to activate an env when your working dir is not cd into the source tree. On the contrary, conda envs are global and easy to activate anywhere.

I primarily work on "project/document" desktop/CLI apps, rather than web apps. It would be nice if I could:

cd ~/path/to/documents (or navigate via file browser, then open terminal in dir)
poetry activate global-editor-env  # same syntax as conda activate
poetry run editor document (or editor document)

instead of:

cd ~/code/editor-app
poetry shell
cd ~/path/to/documents
poetry run editor document` or `editor document

or

  • Open my IDE's terminal in ~/code/editor-app
  • Obtain $dir of virtual env via poetry show -v | head -n 1 (which caused this bug report)...
  • opening another terminal in ~/path/to/documents, running . (paste $dir)/bin/activate or similar...

Should I file another bug report?

@pmav99
Copy link
Contributor

pmav99 commented Feb 9, 2019

You don't have to use poetry to handle virtualenvs. If a virtualenv is active, poetry will be happy to use it. So you can use pew or virtualenvwrapper or (I guess) conda to manage your virtualenvs and let poetry just handle the project's dependencies.

@zmitchell
Copy link

zmitchell commented Feb 9, 2019

Getting back to the actual error you brought up, it looks like you can avoid the error by doing this:

# cleo/outputs/stream_output.py
from signal import signal, SIGPIPE, SIG_DFL
signal(SIGPIPE, SIG_DFL)

This solution is taken from this SO post. In short:

  • SIGPIPE is sent to a process when it tries to write to a pipe that is no longer open.
  • If the process doesn't handle SIGPIPE, then it is terminated.
  • Python catches the SIGPIPE and raises a BrokenPipeError.
  • This solution recovers the default behavior (SIG_DFL, i.e. terminating the process).

I'll create an issue in the cleo repository since this is more related to cleo than poetry.

P.S. - For what it's worth, I don't really do any web development at all, and I use poetry all the time.

@zmitchell
Copy link

It turns out that poetry is using cleo 0.6.8, but the current version is 0.7.2, and there are major changes to the layout of the cleo project between those releases. You can't just make poetry use the newer version of cleo without breaking things, so for the time being I would recommend changing those two lines in your local version of cleo that was installed with poetry.

@stale
Copy link

stale bot commented Nov 13, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 13, 2019
@stale
Copy link

stale bot commented Nov 20, 2019

Closing this issue automatically because it has not had any activity since it has been marked as stale. If you think it is still relevant and should be addressed, feel free to open a new one.

@stale stale bot closed this as completed Nov 20, 2019
Copy link

github-actions bot commented Mar 3, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants