Execute a code object. When an exception occurs, self.showtraceback() is called to display a traceback. All exceptions are caught except SystemExit, which is reraised. A note about KeyboardInterrupt: this exception may occur elsewhere in this code, and may
(self, code)
| 138 | |
| 139 | @overrides(InteractiveConsole.runcode) |
| 140 | def runcode(self, code): |
| 141 | """Execute a code object. |
| 142 | |
| 143 | When an exception occurs, self.showtraceback() is called to |
| 144 | display a traceback. All exceptions are caught except |
| 145 | SystemExit, which is reraised. |
| 146 | |
| 147 | A note about KeyboardInterrupt: this exception may occur |
| 148 | elsewhere in this code, and may not always be caught. The |
| 149 | caller should be prepared to deal with it. |
| 150 | |
| 151 | """ |
| 152 | try: |
| 153 | updated_globals = self.get_namespace() |
| 154 | initial_globals = updated_globals.copy() |
| 155 | |
| 156 | updated_locals = None |
| 157 | |
| 158 | is_async = False |
| 159 | if hasattr(inspect, "CO_COROUTINE"): |
| 160 | is_async = inspect.CO_COROUTINE & code.co_flags == inspect.CO_COROUTINE |
| 161 | |
| 162 | if is_async: |
| 163 | t = _EvalAwaitInNewEventLoop(code, updated_globals, updated_locals) |
| 164 | t.start() |
| 165 | t.join() |
| 166 | |
| 167 | update_globals_and_locals(updated_globals, initial_globals, self.frame) |
| 168 | if t.exc: |
| 169 | raise t.exc[1].with_traceback(t.exc[2]) |
| 170 | |
| 171 | else: |
| 172 | try: |
| 173 | exec(code, updated_globals, updated_locals) |
| 174 | finally: |
| 175 | update_globals_and_locals(updated_globals, initial_globals, self.frame) |
| 176 | except SystemExit: |
| 177 | raise |
| 178 | except: |
| 179 | # In case sys.excepthook called, use original excepthook #PyDev-877: Debug console freezes with Python 3.5+ |
| 180 | # (showtraceback does it on python 3.5 onwards) |
| 181 | sys.excepthook = sys.__excepthook__ |
| 182 | try: |
| 183 | self.showtraceback() |
| 184 | finally: |
| 185 | sys.__excepthook__ = sys.excepthook |
| 186 | |
| 187 | def get_namespace(self): |
| 188 | dbg_namespace = {} |
nothing calls this directly
no test coverage detected