10000 Added comment to output/vt100 regarding isatty. · mxr/python-prompt-toolkit@7d2ef19 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7d2ef19

Browse files
Added comment to output/vt100 regarding isatty.
Also changed isatty() check into a try/except in order to avoid race conditions. (There was still a chance that another thread would turn stdout into a non-tty device.)
1 parent 703dea5 commit 7d2ef19

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

prompt_toolkit/output/vt100.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,14 @@ def get_size() -> Size:
459459
# https://github.com/ipython/ipython/issues/10071
460460
rows, columns = (None, None)
461461

462-
if stdout.isatty():
462+
# It is possible that `stdout` is no longer a TTY device at this
463+
# point. In that case we get an `OSError` in the ioctl call in
464+
# `get_size`. See:
465+
# https://github.com/prompt-toolkit/python-prompt-toolkit/pull/1021
466+
try:
463467
rows, columns = _get_size(stdout.fileno())
468+
except OSError:
469+
pass
464470
return Size(rows=rows or 24, columns=columns or 80)
465471

466472
return cls(stdout, get_size, term=term)

0 commit comments

Comments
 (0)
0