gh-116402: Avoid readline in test_builtin TTY input tests#122447
Merged
ambv merged 5 commits intopython:mainfrom Jul 30, 2024
Merged
gh-116402: Avoid readline in test_builtin TTY input tests#122447ambv merged 5 commits intopython:mainfrom
ambv merged 5 commits intopython:mainfrom
Conversation
Contributor
Author
|
@Eclips4, can you confirm this fixes the issue for you? |
Member
Yes! Thanks for the fix! |
Member
JelleZijlstra
left a comment
There was a problem hiding this comment.
Thanks, this also fixes test_builtin for me locally.
Contributor
Author
|
All buildbots (including refleaks and bigmem) passed save for "iOS ARM64 Simulator" with an unrelated failure. Rebasing on main with the |
|
Thanks @ambv for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Jul 30, 2024
…onGH-122447) (cherry picked from commit 1d8e453) Co-authored-by: Łukasz Langa <lukasz@langa.pl>
|
GH-122472 is a backport of this pull request to the 3.13 branch. |
ambv
added a commit
that referenced
this pull request
Jul 30, 2024
blhsing
pushed a commit
to blhsing/cpython
that referenced
this pull request
Aug 22, 2024
facebook-github-bot
pushed a commit
to facebookincubator/cinder
that referenced
this pull request
Jun 25, 2025
Summary: upstream issue: python/cpython#116402 upstream PR: python/cpython#122447 `test_builtin.test_input_tty` is consistently hanging on macOS when running the full test suite in a single worker, due to an issue with `readline` being imported earlier in the same process. this upstream patch fixes that by temporarily "detaching" readline. here's the upstream PR description: The intention here is to make the TTY `input()` tests run in as many scenarios as possible. For this to happen, we need to temporarily remove the function pointer set to `call_readline` in `PyInit_readline()`. This pointer is normally `NULL` without `readline` and `PyOS_Readline` uses a basic implementation of its own in this case. This is what we want. We could try and avoid importing `readline` in tests, but we have played this whack-a-mole for a long time. For instance, now that `pdb` uses `rlcompleter`, `test_builtin` imports that always (since it imports `doctest` in `load_tests()` and `doctest` imports `pdb` as it subclasses it). I think we should stop trying to not load `readline`, and just detach its function temporarily. This avoids discussions of "unimporting" readline, which would be problematic as `PyInit_readline()` sets global state on the C side through `setup_readline`. While CI is famously not run with a TTY and those tests will be skipped there, people running tests sequentially from their terminal will now be able to have those tests run in many more situations than before. I did the function pointer unsetting with `ctypes` for simplicity. If that's unavailable, the context manager simply skips the tests. Reviewed By: bowiechen Differential Revision: D77306493 fbshipit-source-id: fd9816286865ffd9cdbc3ceb7371402df23a2725
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.
The intention here is to make the TTY
input()tests run in as many scenarios as possible. For this to happen, we need to temporarily remove the function pointer set tocall_readlineinPyInit_readline(). This pointer is normallyNULLwithoutreadlineandPyOS_Readlineuses a basic implementation of its own in this case. This is what we want.We could try and avoid importing
readlinein tests, but we have played this whack-a-mole for a long time. For instance, now thatpdbusesrlcompleter,test_builtinimports that always (since it importsdoctestinload_tests()anddoctestimportspdbas it subclasses it). I think we should stop trying to not loadreadline, and just detach its function temporarily. This avoids discussions of "unimporting" readline, which would be problematic asPyInit_readline()sets global state on the C side throughsetup_readline.While CI is famously not run with a TTY and those tests will be skipped there, people running tests sequentially from their terminal will now be able to have those tests run in many more situations than before.
I did the function pointer unsetting with
ctypesfor simplicity. If that's unavailable, the context manager simply skips the tests.test_builtin.PtyTests.test_input_ttyhangs ifrlcompleteris imported #116402