From d30829def2be7edc649f06d73fdc5a4813e29d1f Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 24 Apr 2016 09:58:43 +0300 Subject: Issue #26801: shutil.get_terminal_size() now handles the case of stdout is reopened on Windows. Added tests for fallbacks. --- Lib/shutil.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Lib/shutil.py') diff --git a/Lib/shutil.py b/Lib/shutil.py index 7f8edf5e5a..37124a0c98 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -1069,7 +1069,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 -- cgit v1.2.1