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

Lost cursor after exception while progress bar is progressing #8825

Open
McSinyx opened this issue Aug 31, 2020 · 0 comments
Open

Lost cursor after exception while progress bar is progressing #8825

McSinyx opened this issue Aug 31, 2020 · 0 comments

Comments

@McSinyx
Copy link
Contributor

McSinyx commented Aug 31, 2020

Environment

  • pip version: 0b18e21
  • Python version: 3.8, but should be irrelevant
  • OS: Debian testing

Description

pip's current implementation of progress bar hides the cursor when it is progressing. There are two ways the cursor is toggled back:

  • At the end of the download
  • On interruption

Other exception, e.g. network timeout (which can be simulated by turning off the system's network in the middle of the download) would leave the terminal without a cursor. I'm not sure if this happens on all terminal emulator but it's the case for at least urxvt.

Posible fix

Making the progress bar a context manager which calls its .finish in __exit__ is likely to solve the issue.

How to Reproduce

  1. Download something that is large enough for one to have the time to act, e.g. pip install tensorflow
  2. Turn off the system's network
  3. ???
  4. Profit

Alternatively one could apply the following patch to current master:

diff --git a/src/pip/_internal/network/download.py b/src/pip/_internal/network/download.py
index 56feaabac..8a16360c3 100644
--- a/src/pip/_internal/network/download.py
+++ b/src/pip/_internal/network/download.py
@@ -206,5 +206,6 @@ class BatchDownloader(object):
             with open(filepath, 'wb') as content_file:
                 for chunk in chunks:
                     content_file.write(chunk)
+                    raise RuntimeError
             content_type = resp.headers.get('Content-Type', '')
             yield link.url, (filepath, content_type)

I am quite familiar with this part of the codebase so I'll submit a patch soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant