Run the REPL loop.
(self)
| 157 | ) |
| 158 | |
| 159 | def run(self) -> None: |
| 160 | """ |
| 161 | Run the REPL loop. |
| 162 | """ |
| 163 | if self.terminal_title: |
| 164 | set_title(self.terminal_title) |
| 165 | |
| 166 | self._add_to_namespace() |
| 167 | |
| 168 | try: |
| 169 | while True: |
| 170 | # Pull text from the user. |
| 171 | try: |
| 172 | text = self.read() |
| 173 | except EOFError: |
| 174 | return |
| 175 | except BaseException: |
| 176 | # Something went wrong while reading input. |
| 177 | # (E.g., a bug in the completer that propagates. Don't |
| 178 | # crash the REPL.) |
| 179 | traceback.print_exc() |
| 180 | continue |
| 181 | |
| 182 | # Run it; display the result (or errors if applicable). |
| 183 | try: |
| 184 | self.run_and_show_expression(text) |
| 185 | except ReplExit: |
| 186 | return |
| 187 | finally: |
| 188 | if self.terminal_title: |
| 189 | clear_title() |
| 190 | self._remove_from_namespace() |
| 191 | |
| 192 | async def run_and_show_expression_async(self, text: str) -> Any: |
| 193 | loop = asyncio.get_running_loop() |
no test coverage detected