Repository navigation
New pyrepl gives a traceback on exit with "dumb" terminal #119102
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on May 16, 2024 - addedtopic-replRelated to the interactive shellRelated to the interactive shell
on May 16, 2024 Looks like the
write_historycallback is registered insite.pyhere:Line 525 in 65de194
def write_history(): def write_history(): try: if os.getenv("PYTHON_BASIC_REPL"): readline.write_history_file(history) else: _pyrepl.readline.write_history_file(history) except (FileNotFoundError, PermissionError): # home directory does not exist or is not writable # https://bugs.python.org/issue19891 pass
It clearly needs to get more clever to detect whether pyrepl is actually in use.
Maybe it can just look at the
_pyrepl.__main__.CAN_USE_PYREPLglobal.@danielhollas
CAN_USE_PYREPLjust checks whether we're on a Windows system, so I wouldn't think checking that would help in this case.Maybe: We set PYTHON_BASIC_REPL to true if TERM is set to "dumb"?
@eugenetriguba if you look at the
_pyrepl/__main__.py,CAN_USE_PYREPLis indeed checking for windows at import, but then later it is set to False if for any reason the new repl cannot be used, on line 41.I tried to fix this by checking CAN_USE_PYREPL in the
write_historycallback function but couldn't make it work -- accessing CAN_USE_PYREPL from__main__module seems to be cursed, and moving it to__init__did not help.Maybe: We set PYTHON_BASIC_REPL to true if TERM is set to "dumb"?
The following patch indeed fixes the issue, happy to make a PR if this seems like a right approach
diff --git a/Lib/_pyrepl/__main__.py b/Lib/_pyrepl/__main__.py index c598019e7c..40cdd6d9fe 100644 --- a/Lib/_pyrepl/__main__.py +++ b/Lib/_pyrepl/__main__.py @@ -39,6 +39,7 @@ def interactive_console(mainmodule=None, quiet=False, pythonstartup=False): trace(msg) print(msg, file=sys.stderr) CAN_USE_PYREPL = False + os.environ["PYTHON_BASIC_REPL"] = "true" if run_interactive is None: return sys._baserepl() return run_interactive(mainmodule)
@danielhollas I worked with @lysnikolaou during PyCon sprints on this one, we came to the same conclusion but he said this is not the best practice to export the env variable to the system. He said he will take a deeper look as to why this might be happening
Reacted by Daniel HollasMaybe add a
site._CAN_USE_PYREPLconstant and modify_pyrepl/__main__.pyto setsite._CAN_USE_PYREPL?Reacted by Lysandros Nikolaou and mi1aclI can do this if it's ok
Reacted by Eugene Triguba and Daniel HollasI proposed PR gh-119269 to fix this issue.
Reacted by mi1aclLeaving this open since #119269 did not fix the problem.
Please check my second fix: PR gh-119332.
- added a commit that references this issue
on May 21, 2024 This time, it should be fixed.
Bug report
Bug description:
I was experimenting with terminal types:
It notices that the terminal is unsuitable, but then tries to use it on exit.
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Linked PRs