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