diff options
author | Milan Oberkirch <milan.oberkirch@geops.com> | 2024-07-16 00:24:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-16 00:24:18 +0200 |
commit | e5c7216f376a06d2c931daf999e2980e494e747e (patch) | |
tree | 6df64e6652cbdaa4e2f6832666f566e75f6a8bf0 /Lib/asyncio/__main__.py | |
parent | d23be3947ced081914f4458c84f729c9c37f0219 (diff) | |
download | cpython-e5c7216f376a06d2c931daf999e2980e494e747e.tar.gz cpython-e5c7216f376a06d2c931daf999e2980e494e747e.zip |
gh-121790: Fix interactive console initialization (#121793)
Co-authored-by: Ćukasz Langa <lukasz@langa.pl>
Diffstat (limited to 'Lib/asyncio/__main__.py')
-rw-r--r-- | Lib/asyncio/__main__.py | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/Lib/asyncio/__main__.py b/Lib/asyncio/__main__.py index 95147171c2b..8b5a4b8f282 100644 --- a/Lib/asyncio/__main__.py +++ b/Lib/asyncio/__main__.py @@ -97,30 +97,16 @@ class REPLThread(threading.Thread): exec(startup_code, console.locals) ps1 = getattr(sys, "ps1", ">>> ") - if can_colorize(): + if can_colorize() and CAN_USE_PYREPL: ps1 = f"{ANSIColors.BOLD_MAGENTA}{ps1}{ANSIColors.RESET}" console.write(f"{ps1}import asyncio\n") - try: - import errno - if os.getenv("PYTHON_BASIC_REPL"): - raise RuntimeError("user environment requested basic REPL") - if not os.isatty(sys.stdin.fileno()): - return_code = errno.ENOTTY - raise OSError(return_code, "tty required", "stdin") - - # This import will fail on operating systems with no termios. + if CAN_USE_PYREPL: from _pyrepl.simple_interact import ( - check, run_multiline_interactive_console, ) - if err := check(): - raise RuntimeError(err) - except Exception as e: - console.interact(banner="", exitmsg="") - else: try: - run_multiline_interactive_console(console=console) + run_multiline_interactive_console(console) except SystemExit: # expected via the `exit` and `quit` commands pass @@ -129,6 +115,8 @@ class REPLThread(threading.Thread): console.showtraceback() console.write("Internal error, ") return_code = 1 + else: + console.interact(banner="", exitmsg="") finally: warnings.filterwarnings( 'ignore', @@ -139,7 +127,10 @@ class REPLThread(threading.Thread): if __name__ == '__main__': - CAN_USE_PYREPL = True + if os.getenv('PYTHON_BASIC_REPL'): + CAN_USE_PYREPL = False + else: + from _pyrepl.main import CAN_USE_PYREPL return_code = 0 loop = asyncio.new_event_loop() |