##// END OF EJS Templates
Refactor part for "%run -d"
Takafumi Arakaki -
Show More
@@ -566,49 +566,8 b' python-profiler package from non-free.""")'
566 stats = self.prun('', code, False, opts, namespace=code_ns)
566 stats = self.prun('', code, False, opts, namespace=code_ns)
567 else:
567 else:
568 if 'd' in opts:
568 if 'd' in opts:
569 deb = debugger.Pdb(self.shell.colors)
569 self._run_with_debugger(
570 # reset Breakpoint state, which is moronically kept
570 code, code_ns, opts.get('b', ['1'])[0], filename)
571 # in a class
572 bdb.Breakpoint.next = 1
573 bdb.Breakpoint.bplist = {}
574 bdb.Breakpoint.bpbynumber = [None]
575 # Set an initial breakpoint to stop execution
576 maxtries = 10
577 bp_file, bp_line = parse_breakpoint(opts.get('b', ['1'])[0], filename)
578 checkline = deb.checkline(bp_file, bp_line)
579 if not checkline:
580 for bp in range(bp_line + 1, bp_line + maxtries + 1):
581 if deb.checkline(bp_file, bp):
582 break
583 else:
584 msg = ("\nI failed to find a valid line to set "
585 "a breakpoint\n"
586 "after trying up to line: %s.\n"
587 "Please set a valid breakpoint manually "
588 "with the -b option." % bp)
589 error(msg)
590 return
591 # if we find a good linenumber, set the breakpoint
592 deb.do_break('%s:%s' % (bp_file, bp_line))
593
594 # Mimic Pdb._runscript(...)
595 deb._wait_for_mainpyfile = True
596 deb.mainpyfile = deb.canonic(filename)
597
598 # Start file run
599 print "NOTE: Enter 'c' at the",
600 print "%s prompt to start your script." % deb.prompt
601 try:
602 #save filename so it can be used by methods on the deb object
603 deb._exec_filename = filename
604 deb.run(code, code_ns)
605
606 except:
607 etype, value, tb = sys.exc_info()
608 # Skip three frames in the traceback: the %run one,
609 # one inside bdb.py, and the command-line typed by the
610 # user (run by exec in pdb itself).
611 self.shell.InteractiveTB(etype, value, tb, tb_offset=3)
612 else:
571 else:
613 if 'm' in opts:
572 if 'm' in opts:
614 def run():
573 def run():
@@ -676,6 +635,51 b' python-profiler package from non-free.""")'
676
635
677 return stats
636 return stats
678
637
638 def _run_with_debugger(self, code, code_ns, break_point, filename):
639 deb = debugger.Pdb(self.shell.colors)
640 # reset Breakpoint state, which is moronically kept
641 # in a class
642 bdb.Breakpoint.next = 1
643 bdb.Breakpoint.bplist = {}
644 bdb.Breakpoint.bpbynumber = [None]
645 # Set an initial breakpoint to stop execution
646 maxtries = 10
647 bp_file, bp_line = parse_breakpoint(break_point, filename)
648 checkline = deb.checkline(bp_file, bp_line)
649 if not checkline:
650 for bp in range(bp_line + 1, bp_line + maxtries + 1):
651 if deb.checkline(bp_file, bp):
652 break
653 else:
654 msg = ("\nI failed to find a valid line to set "
655 "a breakpoint\n"
656 "after trying up to line: %s.\n"
657 "Please set a valid breakpoint manually "
658 "with the -b option." % bp)
659 error(msg)
660 return
661 # if we find a good linenumber, set the breakpoint
662 deb.do_break('%s:%s' % (bp_file, bp_line))
663
664 # Mimic Pdb._runscript(...)
665 deb._wait_for_mainpyfile = True
666 deb.mainpyfile = deb.canonic(filename)
667
668 # Start file run
669 print "NOTE: Enter 'c' at the",
670 print "%s prompt to start your script." % deb.prompt
671 try:
672 #save filename so it can be used by methods on the deb object
673 deb._exec_filename = filename
674 deb.run(code, code_ns)
675
676 except:
677 etype, value, tb = sys.exc_info()
678 # Skip three frames in the traceback: the %run one,
679 # one inside bdb.py, and the command-line typed by the
680 # user (run by exec in pdb itself).
681 self.shell.InteractiveTB(etype, value, tb, tb_offset=3)
682
679 @staticmethod
683 @staticmethod
680 def _run_with_timing(run, nruns):
684 def _run_with_timing(run, nruns):
681 twall0 = time.time()
685 twall0 = time.time()
General Comments 0
You need to be logged in to leave comments. Login now