Message249372
| Author |
rsc1975 |
| Recipients |
rsc1975 |
| Date |
2015年08月30日.22:59:13 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1440975553.42.0.716947211383.issue24966@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2015年08月30日 22:59:13 | rsc1975 | set | recipients:
+ rsc1975 |
| 2015年08月30日 22:59:13 | rsc1975 | set | messageid: <1440975553.42.0.716947211383.issue24966@psf.upfronthosting.co.za> |
| 2015年08月30日 22:59:13 | rsc1975 | link | issue24966 messages |
| 2015年08月30日 22:59:13 | rsc1975 | create |
|