Make os.get_terminal_size check isatty before calling ioctl - #154885
Merged
Conversation
os.get_terminal_size check isatty before ioctlos.get_terminal_size check isatty before calling ioctl
mhsmith
marked this pull request as ready for review
July 29, 2026 16:17
Member
Author
|
Confirmed that the relevant test is skipped on Android: And still passes on macOS: % ./cross-build/build/python.exe -c 'import os; print(os.get_terminal_size())'
os.terminal_size(columns=193, lines=63 |
freakboy3742
approved these changes
Jul 30, 2026
freakboy3742
left a comment
Contributor
There was a problem hiding this comment.
Makes sense to me 👍
Agreed that this doesn't meet the requirements for a backport to stable releases; but I've back ported to 3.15 because it will be an appreciable quality-of-life improvement, and 3.15 isn't final yet.
freakboy3742
enabled auto-merge (squash)
July 30, 2026 02:04
|
Thanks @mhsmith for the PR, and @freakboy3742 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15. |
|
GH-154903 is a backport of this pull request to the 3.15 branch. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Android, stdout is probably not connected, and calling
ioctl(TIOCGWINSZ)on an invalid file descriptor causes a log message "avc: denied { ioctl }", and returns EACCES. This still meets the specification ofget_terminal_size, which only says it throws an OSError.However, the log noise can be a problem. You can see it in this run of the CPython test suite, mostly in tests that involve
argparse, such astest_ast. Some common tools such as pytest are even worse affected, as they callget_terminal_sizevery often.So this PR adds an
isattycheck before calingioctl. This should be harmless on other platforms, so I haven't made it Android-specific.This isn't a bugfix, so it shouldn't be backported.