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

Pip: Wrong Showing of Progressbar when Downloading Modules #8852

Open
jifbt opened this issue Sep 8, 2020 · 3 comments
Open

Pip: Wrong Showing of Progressbar when Downloading Modules #8852

jifbt opened this issue Sep 8, 2020 · 3 comments
Labels
project: vendored dependency Related to a vendored dependency

Comments

@jifbt
Copy link

jifbt commented Sep 8, 2020

First reported from https://bugs.python.org/issue41651.

Environment

  • pip version: 20.1.1
  • Python version: 3.8.2 (release)
  • OS: Windows 7 64-bit

Description

Command line in Windows the progress bar doesn't work like usual after about half of the downloading process.
Another remarkble bug is the length of the progressbar seems to be lengthened.

Expected behavior

The progress bar is expected to be deleted completely, but sometimes it isn't.

How to Reproduce

  1. Run py -m pip install ... or any method to download/update packages via pip.
  2. The error above occurs.

Reason(my opinion)

I noticed that this bug only happens when the rightmost character reaches the end of the cmd screen. I infer the reason of this bug from the phenomenon: when the progres bar is going to be lengthened, pip will delete the last line. Pip consider the line as an enter that the program output. However, the cmd consider the line as an enter whether it is output by the program or added by cmd itself because of the rightmost character reaches the end of the cmd screen. When pip make cmd delete the last line, pip want cmd to delete the whole progressbar, but cmd only deletes a part of the progressbar which are in the line 2.

Output

An instance of the bug, showing what happenred when upgrading pip via py -m pip install --upgrade pip. You can see the progress bar wasn't deleted completly.
The deleted progressbar isn't shown.


C:\Users\******>py -m pip install --upgrade pip
Collecting pip
  Downloading pip-20.2.2-py2.py3-none-any.whl (1.5 MB)
     |█████████████▌                  | 634 kB 21 kB/s eta 0:00:41
     |██████████████                  | 645 kB 21 kB/s eta 0:00:41
     |██████████████                  | 655 kB 21 kB/s eta 0:00:40
     |██████████████                  | 665 kB 21 kB/s eta 0:00:40
     |██████████████▌                 | 675 kB 23 kB/s eta 0:00:3
     |██████████████▌                 | 686 kB 23 kB/s eta 0:00:3
     |███████████████                 | 696 kB 23 kB/s eta 0:00:3
     |███████████████                 | 706 kB 33 kB/s eta 0:00:2
     |███████████████                 | 716 kB 33 kB/s eta 0:00:2
     |███████████████▌                | 727 kB 28 kB/s eta 0:00:
     |████████████████                | 737 kB 28 kB/s eta 0:00:
     |████████████████                | 747 kB 28 kB/s eta 0:00:
     |████████████████                | 757 kB 23 kB/s eta 0:00:
     |████████████████▌               | 768 kB 23 kB/s eta 0:00
     |████████████████▌               | 778 kB 23 kB/s eta 0:00
     |█████████████████               | 788 kB 20 kB/s eta 0:00
     |█████████████████               | 798 kB 20 kB/s eta 0:00
     |█████████████████               | 808 kB 20 kB/s eta 0:00
     |█████████████████▌              | 819 kB 20 kB/s eta 0:0
     |█████████████████▌              | 829 kB 20 kB/s eta 0:0
     |██████████████████              | 839 kB 25 kB/s eta 0:0
     |██████████████████              | 849 kB 25 kB/s eta 0:0
     |██████████████████              | 860 kB 19 kB/s eta 0:0
     |██████████████████▌             | 870 kB 19 kB/s eta 0:
     |███████████████████             | 880 kB 17 kB/s eta 0:
     |███████████████████             | 890 kB 17 kB/s eta 0:
     |███████████████████             | 901 kB 17 kB/s eta 0:
     |███████████████████▌            | 911 kB 17 kB/s eta 0
     |███████████████████▌            | 921 kB 17 kB/s eta 0
     |████████████████████            | 931 kB 12 kB/s eta 0
     |████████████████████            | 942 kB 12 kB/s eta 0
     |████████████████████            | 952 kB 12 kB/s eta 0
     |████████████████████▌           | 962 kB 13 kB/s eta
     |█████████████████████           | 972 kB 13 kB/s eta
     |█████████████████████           | 983 kB 8.9 kB/s eta
     |█████████████████████           | 993 kB 6.7 kB/s eta
     |█████████████████████▌          | 1.0 MB 6.7 kB/s et
     |█████████████████████▌          | 1.0 MB 6.7 kB/s et
     |██████████████████████          | 1.0 MB 6.7 kB/s et
     |██████████████████████          | 1.0 MB 6.7 kB/s et
     |██████████████████████          | 1.0 MB 8.4 kB/s et
     |██████████████████████▌         | 1.1 MB 8.4 kB/s e
     |██████████████████████▌         | 1.1 MB 8.4 kB/s e
     |███████████████████████         | 1.1 MB 8.8 kB/s e
     |███████████████████████         | 1.1 MB 8.8 kB/s e
     |███████████████████████         | 1.1 MB 24 kB/s et
     |███████████████████████▌        | 1.1 MB 24 kB/s e
     |████████████████████████        | 1.1 MB 16 kB/s e
     |████████████████████████        | 1.1 MB 16 kB/s e
     |████████████████████████        | 1.1 MB 14 kB/s e
     |████████████████████████▌       | 1.1 MB 14 kB/s
     |████████████████████████▌       | 1.2 MB 14 kB/s
     |█████████████████████████       | 1.2 MB 14 kB/s
     |█████████████████████████       | 1.2 MB 12 kB/s
     |█████████████████████████       | 1.2 MB 12 kB/s
     |█████████████████████████▌      | 1.2 MB 12 kB/s
     |██████████████████████████      | 1.2 MB 12 kB/s
     |██████████████████████████      | 1.2 MB 12 kB/s
     |██████████████████████████      | 1.2 MB 19 kB/s
     |██████████████████████████▌     | 1.2 MB 19 kB/
     |██████████████████████████▌     | 1.2 MB 20 kB/
     |███████████████████████████     | 1.3 MB 15 kB/
     |███████████████████████████     | 1.3 MB 15 kB/
     |███████████████████████████     | 1.3 MB 15 kB/
     |███████████████████████████▌    | 1.3 MB 15 kB
     |████████████████████████████    | 1.3 MB 20 kB
     |████████████████████████████    | 1.3 MB 20 kB
     |████████████████████████████    | 1.3 MB 14 kB
     |████████████████████████████    | 1.3 MB 14 kB
     |████████████████████████████▌   | 1.3 MB 14 k
     |█████████████████████████████   | 1.4 MB 14 k
     |█████████████████████████████   | 1.4 MB 14 k
     |█████████████████████████████   | 1.4 MB 14 k
     |█████████████████████████████▌  | 1.4 MB 14
     |█████████████████████████████▌  | 1.4 MB 14
     |██████████████████████████████  | 1.4 MB 12
     |██████████████████████████████  | 1.4 MB 9.4
     |██████████████████████████████  | 1.4 MB 9.4
     |██████████████████████████████▌ | 1.4 MB 9.
     |███████████████████████████████ | 1.4 MB 9.
     |███████████████████████████████ | 1.5 MB 9.
     |███████████████████████████████ | 1.5 MB 11
     |███████████████████████████████▌| 1.5 MB 1
     |███████████████████████████████▌| 1.5 MB 1
     |████████████████████████████████| 1.5 MB 1
     |████████████████████████████████| 1.5 MB 1
4 kB/s
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 20.1.1
    Uninstalling pip-20.1.1:
      Successfully uninstalled pip-20.1.1
  WARNING: The scripts pip.exe, pip3.8.exe and pip3.exe are installed in 'C:\Use
rs\Administrator\AppData\Local\Programs\Python\Python38\Scripts' which is not on
 PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warn
ing, use --no-warn-script-location.
Successfully installed pip-20.2.2

C:\Users\******>
@McSinyx
Copy link
Contributor

McSinyx commented Sep 8, 2020

Thank you for reporting this. If possible, could you also provide a screencast as well since it would make the problem more intuitive to understand.

@eryksun
Copy link

eryksun commented Sep 8, 2020

This appears to be the expected behavior with the default-enabled console mode that wraps at the end of a line. For example, if the screen buffer is 70 characters wide, and a line is written to the console with 70 characters or more, then returning to the start by writing a CR won't work because the cursor has already advanced to the next line.

>>> print('a'*70, 'b'*70, sep='\r')
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

It shouldn't be an issue if the line length is always less than the screen-buffer width.

>>> shutil.get_terminal_size().columns
70
>>> print('a'*69, 'b'*69, sep='\r')
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

Wrapping at the end of the line can also be disabled.

import sys, ctypes, msvcrt
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)

ENABLE_WRAP_AT_EOL_OUTPUT = 2

h = msvcrt.get_osfhandle(sys.stdout.fileno())
mode = ctypes.c_ulong()
kernel32.GetConsoleMode(h, ctypes.byref(mode))
mode.value &= ~ENABLE_WRAP_AT_EOL_OUTPUT
kernel32.SetConsoleMode(h, mode)
>>> print('a'*1000, 'b'*70, sep='\r')
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

@uranusjr
Copy link
Member

uranusjr commented Sep 8, 2020

verigak/progress#40 covers this. Per pip’s vendoring policy, we should persue a fix in upstream first.

@uranusjr uranusjr added the project: vendored dependency Related to a vendored dependency label Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
project: vendored dependency Related to a vendored dependency
Projects
None yet
Development

No branches or pull requests

4 participants