Run `code` in debugger with a break point. Parameters ---------- code : str Code to execute. code_ns : dict A namespace in which `code` is executed. filename : str `code` is ran as if it is in `filename`. b
(
self, code, code_ns, filename=None, bp_line=None, bp_file=None, local_ns=None
)
| 914 | return stats |
| 915 | |
| 916 | def _run_with_debugger( |
| 917 | self, code, code_ns, filename=None, bp_line=None, bp_file=None, local_ns=None |
| 918 | ): |
| 919 | """ |
| 920 | Run `code` in debugger with a break point. |
| 921 | |
| 922 | Parameters |
| 923 | ---------- |
| 924 | code : str |
| 925 | Code to execute. |
| 926 | code_ns : dict |
| 927 | A namespace in which `code` is executed. |
| 928 | filename : str |
| 929 | `code` is ran as if it is in `filename`. |
| 930 | bp_line : int, optional |
| 931 | Line number of the break point. |
| 932 | bp_file : str, optional |
| 933 | Path to the file in which break point is specified. |
| 934 | `filename` is used if not given. |
| 935 | local_ns : dict, optional |
| 936 | A local namespace in which `code` is executed. |
| 937 | |
| 938 | Raises |
| 939 | ------ |
| 940 | UsageError |
| 941 | If the break point given by `bp_line` is not valid. |
| 942 | |
| 943 | """ |
| 944 | deb = self.shell.InteractiveTB.pdb |
| 945 | if not deb: |
| 946 | self.shell.InteractiveTB.pdb = self.shell.InteractiveTB.debugger_cls() |
| 947 | deb = self.shell.InteractiveTB.pdb |
| 948 | |
| 949 | # reset Breakpoint state, which is moronically kept |
| 950 | # in a class |
| 951 | bdb.Breakpoint.next = 1 |
| 952 | bdb.Breakpoint.bplist = {} |
| 953 | bdb.Breakpoint.bpbynumber = [None] |
| 954 | deb.clear_all_breaks() |
| 955 | if bp_line is not None: |
| 956 | # Set an initial breakpoint to stop execution |
| 957 | maxtries = 10 |
| 958 | bp_file = bp_file or filename |
| 959 | checkline = deb.checkline(bp_file, bp_line) |
| 960 | if not checkline: |
| 961 | for bp in range(bp_line + 1, bp_line + maxtries + 1): |
| 962 | if deb.checkline(bp_file, bp): |
| 963 | break |
| 964 | else: |
| 965 | msg = ("\nI failed to find a valid line to set " |
| 966 | "a breakpoint\n" |
| 967 | "after trying up to line: %s.\n" |
| 968 | "Please set a valid breakpoint manually " |
| 969 | "with the -b option." % bp) |
| 970 | raise UsageError(msg) |
| 971 | # if we find a good linenumber, set the breakpoint |
| 972 | deb.do_break('%s:%s' % (bp_file, bp_line)) |
| 973 |
no test coverage detected