[issue24966] shutil.get_terminal_size() throws ValueError is stdout is detached, no fallback
Roberto Sánchez
report at bugs.python.org
Mon Aug 31 00:59:13 CEST 2015
New submission from Roberto Sánchez:
After the stdout stream has been overwritten and detached, the method shutils.get_terminal_size throws a ValueError exception and no fallback value is returned.
Code to reproduce it:
>>> import os, sys, codecs, shutils
>>> sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
>>> os.get_terminal_size()
os.terminal_size(columns=160, lines=37)
>>> shutil.get_terminal_size((200, 30))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python3.4/shutil.py", line 1057, in get_terminal_size
size = os.get_terminal_size(sys.__stdout__.fileno())
ValueError: underlying buffer has been detached
Is this the expected behavior ? IMHO, the given fallback values should be returned.
The official doc: "If the terminal size cannot be successfully queried, either because the system doesn’t support querying, or because we are not connected to a terminal, the value given in fallback parameter is used. fallback defaults to (80, 24) which is the default size used by many terminal emulators"
BTW, the function os.get_terminal_size() returns the correct size when it's invoked without parameters, maybe It could be a good fallback if sys.__stdout__ is not available and there isn't any user fallback values.
----------
components: IO
messages: 249372
nosy: rsc1975
priority: normal
severity: normal
status: open
title: shutil.get_terminal_size() throws ValueError is stdout is detached, no fallback
type: behavior
versions: Python 3.4
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24966>
_______________________________________
More information about the Python-bugs-list
mailing list