| 582 | self.locals = {} |
| 583 | |
| 584 | def runcode(self, code): |
| 585 | global interruptible |
| 586 | try: |
| 587 | self.user_exc_info = None |
| 588 | interruptible = True |
| 589 | try: |
| 590 | exec(code, self.locals) |
| 591 | finally: |
| 592 | interruptible = False |
| 593 | except SystemExit as e: |
| 594 | if e.args: # SystemExit called with an argument. |
| 595 | ob = e.args[0] |
| 596 | if not isinstance(ob, (type(None), int)): |
| 597 | print('SystemExit: ' + str(ob), file=sys.stderr) |
| 598 | # Return to the interactive prompt. |
| 599 | except: |
| 600 | self.user_exc_info = sys.exc_info() # For testing, hook, viewer. |
| 601 | if quitting: |
| 602 | exit() |
| 603 | if sys.excepthook is sys.__excepthook__: |
| 604 | print_exception() |
| 605 | else: |
| 606 | try: |
| 607 | sys.excepthook(*self.user_exc_info) |
| 608 | except: |
| 609 | self.user_exc_info = sys.exc_info() # For testing. |
| 610 | print_exception() |
| 611 | jit = self.rpchandler.console.getvar("<<toggle-jit-stack-viewer>>") |
| 612 | if jit: |
| 613 | self.rpchandler.interp.open_remote_stack_viewer() |
| 614 | else: |
| 615 | flush_stdout() |
| 616 | |
| 617 | def interrupt_the_server(self): |
| 618 | if interruptible: |