rsalmei / alive-progress

A new kind of Progress Bar, with real-time throughput, ETA, and very cool animations!
MIT License
5.53k stars 206 forks source link

OSError: [WinError 6] when running in MSys2 Bash Terminal #163

Closed j-zeppenfeld closed 2 years ago

j-zeppenfeld commented 2 years ago

When running an alive-progress bar in MSys2 Bash, the following error occurs:

...
  File "C:/msys64/mingw64/lib/python3.9/site-packages/alive_progress/core/progress.py", line 266, in __alive_bar
    alive_repr()
  File "C:/msys64/mingw64/lib/python3.9/site-packages/alive_progress/core/progress.py", line 123, in alive_repr
    run.last_len = print_cells(fragments, term.cols(), run.last_len, _term=term)
  File "C:/msys64/mingw64/lib/python3.9/site-packages/alive_progress/utils/terminal/tty.py", line 32, in cols
    return os.get_terminal_size()[0]
OSError: [WinError 6] Das Handle ist ung▒ltig

Running os.get_terminal_size() directly in the python3 console produces the same error.

Python 3.9.6 (default, Aug 15 2021, 14:49:43)  [GCC 10.3.0 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.get_terminal_size()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [WinError 6] Das Handle ist ung▒ltig

Using shutil.get_terminal_size() instead works as intended.

Python 3.9.6 (default, Aug 15 2021, 14:49:43)  [GCC 10.3.0 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import shutil
>>> shutil.get_terminal_size()
os.terminal_size(columns=80, lines=24)
j-zeppenfeld commented 2 years ago

Apparently this is already fixed for tty.py, but there is still an instance of os.get_terminal_size in styles/exhibit.py.

rsalmei commented 2 years ago

Wow, that's really odd... 😕 What does that message say? In English.

For tty.py, I wouldn't say it was "fixed", I was kinda forced to use it because of some exoteric terminals out there, but it is several times slower than the os one.

I might dynamically test it for the next version then... If it does not break and returns something non-zero, I'll use it. Otherwise I'll switch to shutil one 😓

rsalmei commented 2 years ago

Oh, another detail, the shutil.get_terminal_size() is not "working as intended". Actually, it just tests if the terminal has an env var with the size, and if not it protects the call to the os one within a try/catch, and if that also fails, it just returns a default (80, 24).

j-zeppenfeld commented 2 years ago

Yeah, I realized that too after posting the comment. It doesn't work, but at least it doesn't break things.

The German text simply states "OSError: [WinError 6] The handle is invalid"

rsalmei commented 2 years ago

What version are you using? I do not use os.get_terminal_size() for a long time, perhaps your version is outdated.

TheTechRobo commented 2 years ago

What version are you using? I do not use os.get_terminal_size() for a long time, perhaps your version is outdated.

They're right: https://github.com/rsalmei/alive-progress/blob/3c5cc00e8b29e1813480292a2f5bb2d6414f2932/alive_progress/styles/exhibit.py#L168

rsalmei commented 2 years ago

That's in exhibit only. The stacktrace you posted first was on terminal/tty.py, called by core, which doesn't exist for a long time...

 File "C:/msys64/mingw64/lib/python3.9/site-packages/alive_progress/core/progress.py", line 266, in __alive_bar
   alive_repr()
 File "C:/msys64/mingw64/lib/python3.9/site-packages/alive_progress/core/progress.py", line 123, in alive_repr
   run.last_len = print_cells(fragments, term.cols(), run.last_len, _term=term)
 File "C:/msys64/mingw64/lib/python3.9/site-packages/alive_progress/utils/terminal/tty.py", line 32, in cols
   return os.get_terminal_size()[0]
TheTechRobo commented 2 years ago

They said this:

Apparently this is already fixed for tty.py, but there is still an instance of os.get_terminal_size in styles/exhibit.py.

That implies they updated and solved the problem, but styles/exhibit.py still has the function. At least, I think.

rsalmei commented 2 years ago

Well, I hope so. But I wanted to understand it better, since that change was a long time ago... Closing this one then.