You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[macOS] test_builtin.PtyTests.test_input_tty hangs if rlcompleter is imported #116402
If we skip import of rlcompleter in the test_all, then everything will be fine:
diff --git a/Lib/test/test___all__.py b/Lib/test/test___all__.py
index 19dcbb207e..c5bf4bb1ff 100644
--- a/Lib/test/test___all__.py+++ b/Lib/test/test___all__.py@@ -111,6 +111,8 @@ def test_all(self):
lib_dir = os.path.dirname(os.path.dirname(__file__))
for path, modname in self.walk_modules(lib_dir, ""):
m = modname
+ if m == "rlcompleter":+ continue
denied = False
while m:
if m in denylist:
Seems like problem in this import:
(sources of Lib/rlcompleter.py)
try:
importreadlineexceptImportError:
_readline_available=Falseelse:
readline.set_completer(Completer().complete)
# Release references early at shutdown (the readline module's# contents are quasi-immortal, and the completer function holds a# reference to globals).atexit.register(lambda: readline.set_completer(None))
_readline_available=True
changed the title [-]``test_builtin`` hangs when running the full test suite[/-][+]``test_builtin.PtyTests.test_input_tty`` hangs when run after test___all__[/+]on Mar 6, 2024
test.test_builtin.PtyTests.test_input_tty can also be affected by other tests that import rlcompleter, and importing rlcompleter can also affect other tests. There may be several old issues which will be solved when solve this issue.
I would add a code that restores (or just resets) the completer in Lib/test/libregrtest/save_env.py.
Reacted by Victor Stinner, Kirill Podoprigora and Łukasz Langa
changed the title [-]``test_builtin.PtyTests.test_input_tty`` hangs when run after test___all__[/-][+]``test_builtin.PtyTests.test_input_tty`` hangs if ``rlcompleter`` is imported[/+]on May 31, 2024
What I'm seeing is related to #112950, which made it so pdb unconditionally imports rlcompleter; test_builtin imports doctest which imports pdb which now imports rlcompleter. However, obviously there are many code paths that could cause rlcompleter to be imported when this test runs.
I tried locally to temporarily set the readline completer to None as @vstinner suggests above, but the test still hangs. I haven't looked more deeply to figure out what's going wrong.
If I comment out the import of readline in rlcompleter.py, the test in test_builtin no longer hangs. But getting rid of the readline.set_completer() call in rlcompleter.py is not sufficient to stop the test from hanging: just readline being present in sys.modules is sufficient to cause the hang.
I see that many similar tests in test_builtin.py are simply skipped if "readline" is present in sys.modules:
We could consider doing something similar here, though obviously it would be nice if the test could still be run even if readline is present in sys.modules.
changed the title [-]``test_builtin.PtyTests.test_input_tty`` hangs if ``rlcompleter`` is imported[/-][+][macOS] ``test_builtin.PtyTests.test_input_tty`` hangs if ``rlcompleter`` is imported[/+]on Jun 2, 2024
Activity
Eclips4 commentedon Mar 6, 2024
Reduced amount of tests to trigger the hang:
sobolevn commentedon Mar 6, 2024
Minimal number of tests:
It gets stuck here:
cpython/Lib/test/test_builtin.py
Line 2282 in d2f1b0e
sobolevn commentedon Mar 6, 2024
Since
test_allactually imports all modules and executes them, the problem can be in any module :(sobolevn commentedon Mar 6, 2024
I think that it would be easier to bisect when running only two test cases at least!
Eclips4 commentedon Mar 6, 2024
If we skip import of
rlcompleterin thetest_all, then everything will be fine:Eclips4 commentedon Mar 6, 2024
Seems like problem in this import:
(sources of
Lib/rlcompleter.py)vstinner commentedon Mar 6, 2024
If a test fails with a completer callback is set, you can try to:
But only do it if readline is in
sys.modules.[-]``test_builtin`` hangs when running the full test suite[/-][+]``test_builtin.PtyTests.test_input_tty`` hangs when run after test___all__[/+]serhiy-storchaka commentedon Mar 6, 2024
test.test_builtin.PtyTests.test_input_ttycan also be affected by other tests that importrlcompleter, and importingrlcompletercan also affect other tests. There may be several old issues which will be solved when solve this issue.I would add a code that restores (or just resets) the completer in
Lib/test/libregrtest/save_env.py.vstinner commentedon Mar 6, 2024
If you fully want to control the TTY and not be affected by previous tests, another approach is to spawn a new process.
ronaldoussoren commentedon Mar 6, 2024
This might be a duplicate of #89050
JelleZijlstra commentedon May 31, 2024
This test hangs for me on a Mac even without running any other test:
[-]``test_builtin.PtyTests.test_input_tty`` hangs when run after test___all__[/-][+]``test_builtin.PtyTests.test_input_tty`` hangs if ``rlcompleter`` is imported[/+]JelleZijlstra commentedon May 31, 2024
What I'm seeing is related to #112950, which made it so
pdbunconditionally importsrlcompleter;test_builtinimportsdoctestwhich importspdbwhich now importsrlcompleter. However, obviously there are many code paths that could causerlcompleterto be imported when this test runs.I tried locally to temporarily set the readline completer to None as @vstinner suggests above, but the test still hangs. I haven't looked more deeply to figure out what's going wrong.
AlexWaygood commentedon May 31, 2024
If I comment out the import of
readlineinrlcompleter.py, the test intest_builtinno longer hangs. But getting rid of thereadline.set_completer()call inrlcompleter.pyis not sufficient to stop the test from hanging: justreadlinebeing present insys.modulesis sufficient to cause the hang.I see that many similar tests in
test_builtin.pyare simply skipped if"readline"is present insys.modules:cpython/Lib/test/test_builtin.py
Line 2400 in 64ff1e2
cpython/Lib/test/test_builtin.py
Line 2405 in 64ff1e2
cpython/Lib/test/test_builtin.py
Line 2415 in 64ff1e2
We could consider doing something similar here, though obviously it would be nice if the test could still be run even if
readlineis present insys.modules.[-]``test_builtin.PtyTests.test_input_tty`` hangs if ``rlcompleter`` is imported[/-][+][macOS] ``test_builtin.PtyTests.test_input_tty`` hangs if ``rlcompleter`` is imported[/+]pythongh-116402: Avoid readline in test_builtin TTY input tests
Merge branch 'main' into pythongh-116402
gh-116402: Avoid readline in test_builtin TTY input tests (GH-122447)
pythongh-116402: Avoid readline in test_builtin TTY input tests (pyth…
[3.13] gh-116402: Avoid readline in test_builtin TTY input tests (GH-…
pythongh-116402: Avoid readline in test_builtin TTY input tests (pyth…
Backport gh-116402: Avoid readline in test_builtin TTY input tests