Debug a statement executed via the exec() function. globals defaults to __main__.dict; locals defaults to globals.
(self, cmd, globals=None, locals=None)
| 583 | # Both can be given as a string, or a code object. |
| 584 | |
| 585 | def run(self, cmd, globals=None, locals=None): |
| 586 | """Debug a statement executed via the exec() function. |
| 587 | |
| 588 | globals defaults to __main__.dict; locals defaults to globals. |
| 589 | """ |
| 590 | if globals is None: |
| 591 | import __main__ |
| 592 | globals = __main__.__dict__ |
| 593 | if locals is None: |
| 594 | locals = globals |
| 595 | self.reset() |
| 596 | if isinstance(cmd, str): |
| 597 | cmd = compile(cmd, "<string>", "exec") |
| 598 | sys.settrace(self.trace_dispatch) |
| 599 | try: |
| 600 | exec(cmd, globals, locals) |
| 601 | except BdbQuit: |
| 602 | pass |
| 603 | finally: |
| 604 | self.quitting = True |
| 605 | sys.settrace(None) |
| 606 | |
| 607 | def runeval(self, expr, globals=None, locals=None): |
| 608 | """Debug an expression executed via the eval() function. |