| 81 | return self.STATEMENT_FAILED |
| 82 | |
| 83 | class REPLThread(threading.Thread): |
| 84 | |
| 85 | def run(self): |
| 86 | global return_code |
| 87 | |
| 88 | try: |
| 89 | banner = ( |
| 90 | f'asyncio REPL {sys.version} on {sys.platform}\n' |
| 91 | f'Use "await" directly instead of "asyncio.run()".\n' |
| 92 | f'Type "help", "copyright", "credits" or "license" ' |
| 93 | f'for more information.\n' |
| 94 | ) |
| 95 | |
| 96 | console.write(banner) |
| 97 | |
| 98 | if startup_path := os.getenv("PYTHONSTARTUP"): |
| 99 | sys.audit("cpython.run_startup", startup_path) |
| 100 | |
| 101 | import tokenize |
| 102 | with tokenize.open(startup_path) as f: |
| 103 | startup_code = compile(f.read(), startup_path, "exec") |
| 104 | exec(startup_code, console.locals) |
| 105 | |
| 106 | ps1 = getattr(sys, "ps1", ">>> ") |
| 107 | if CAN_USE_PYREPL: |
| 108 | theme = get_theme().syntax |
| 109 | ps1 = f"{theme.prompt}{ps1}{theme.reset}" |
| 110 | console.write(f"{ps1}import asyncio\n") |
| 111 | |
| 112 | if CAN_USE_PYREPL: |
| 113 | from _pyrepl.simple_interact import ( |
| 114 | run_multiline_interactive_console, |
| 115 | ) |
| 116 | try: |
| 117 | run_multiline_interactive_console(console) |
| 118 | except SystemExit: |
| 119 | # expected via the `exit` and `quit` commands |
| 120 | pass |
| 121 | except BaseException: |
| 122 | # unexpected issue |
| 123 | console.showtraceback() |
| 124 | console.write("Internal error, ") |
| 125 | return_code = 1 |
| 126 | else: |
| 127 | console.interact(banner="", exitmsg="") |
| 128 | finally: |
| 129 | warnings.filterwarnings( |
| 130 | 'ignore', |
| 131 | message=r'^coroutine .* was never awaited$', |
| 132 | category=RuntimeWarning) |
| 133 | |
| 134 | loop.call_soon_threadsafe(loop.stop) |
| 135 | |
| 136 | def interrupt(self) -> None: |
| 137 | if not CAN_USE_PYREPL: |
| 138 | return |
| 139 | |
| 140 | from _pyrepl.simple_interact import _get_reader |