Issue #26801: shutil.get_terminal_size() now handles the case of stdout is

reopened on Windows.  Added tests for fallbacks.
This commit is contained in:
Serhiy Storchaka 2016-04-24 09:59:17 +03:00
commit 18a8affc8e
2 changed files with 32 additions and 1 deletions

View file

@ -1072,7 +1072,9 @@ def get_terminal_size(fallback=(80, 24)):
if columns <= 0 or lines <= 0:
try:
size = os.get_terminal_size(sys.__stdout__.fileno())
except (AttributeError, OSError):
except (AttributeError, ValueError, OSError):
# stdout is None, closed, detached, or not a terminal, or
# os.get_terminal_size() is unsupported
size = os.terminal_size(fallback)
if columns <= 0:
columns = size.columns