当前位置: 首页>>代码示例>>Python>>正文


Python debugger.Pdb类代码示例

本文整理汇总了Python中IPython.core.debugger.Pdb的典型用法代码示例。如果您正苦于以下问题:Python Pdb类的具体用法?Python Pdb怎么用?Python Pdb使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Pdb类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: debug

def debug(f, *args, **kwargs):
    """
    Allows the user to launch pdb in any function.

    Parameters
    ----------
    f: function
        The function you wish to debug

    args:
        The arguments that need to be passed to f

    kwargs:
        Named arguments that must be passed to f

    Returns
    -------
    None

    Notes
    -----
    Taken from Wes McKinney's book Python for Data Analysis
    """
    from IPython.core.debugger import Pdb
    pdb = Pdb(color_scheme='Linux')
    return pdb.runcall(f, *args, **kwargs)
开发者ID:spencerlyon2,项目名称:pytools,代码行数:26,代码来源:ipython_debug.py

示例2: trace

def trace():
    """like pdb.set_trace() except sets a breakpoint for the next line
    
    works with nose testing framework (uses sys.__stdout__ for output)
    """
    frame = sys._getframe().f_back
    pdb = Pdb(color_scheme='Linux', stdout=sys.__stdout__)
    pdb.set_trace(frame)
开发者ID:jagguli,项目名称:PyBug,代码行数:8,代码来源:bug.py

示例3: post_mortem

def post_mortem(tb):
    ip = ipapi.get()
    def_colors = ip.colors
    p = Pdb(def_colors)
    p.reset()
    while tb.tb_next is not None:
        tb = tb.tb_next
    p.interaction(tb.tb_frame, tb)
开发者ID:pkimber,项目名称:my-memory,代码行数:8,代码来源:ipdb.py

示例4: post_mortem

def post_mortem(tb):
    update_stdout()
    wrap_sys_excepthook()
    p = Pdb(def_colors)
    p.reset()
    if tb is None:
        return
    p.interaction(None, tb)
开发者ID:omergertel,项目名称:ipdb,代码行数:8,代码来源:__main__.py

示例5: debug

def debug(f, *args, **kwargs):
    from pdb import Pdb as OldPdb
    try:
        from IPython.core.debugger import Pdb
        kw = dict(color_scheme='Linux')
    except ImportError:
        Pdb = OldPdb
        kw = {}
    pdb = Pdb(**kw)
    return pdb.runcall(f, *args, **kwargs)
开发者ID:takluyver,项目名称:pandas,代码行数:10,代码来源:testing.py

示例6: post_mortem

def post_mortem(tb):
    update_stdout()
    wrap_sys_excepthook()
    p = Pdb(def_colors)
    p.reset()
    if tb is None:
        return
    while tb.tb_next is not None:
        tb = tb.tb_next
    p.interaction(tb.tb_frame, tb)
开发者ID:dmsul,项目名称:ipdb,代码行数:10,代码来源:__main__.py

示例7: post_mortem

def post_mortem(tb):
    update_stdout()
    sys.excepthook = lambda et, ev, tb, orig_hook=sys.excepthook: \
      BdbQuit_excepthook(et, ev, tb, orig_hook)
    p = Pdb(def_colors)
    p.reset()
    if tb is None:
        return
    while tb.tb_next is not None:
        tb = tb.tb_next
    p.interaction(tb.tb_frame, tb)
开发者ID:DamianHeard,项目名称:ipdb,代码行数:11,代码来源:__main__.py

示例8: post_mortem

def post_mortem(tb):
    update_stdout()
    BdbQuit_excepthook.excepthook_ori = sys.excepthook
    sys.excepthook = BdbQuit_excepthook
    p = Pdb(def_colors)
    p.reset()
    if tb is None:
        return
    while tb.tb_next is not None:
        tb = tb.tb_next
    p.interaction(tb.tb_frame, tb)
开发者ID:moon2l,项目名称:ipdb,代码行数:11,代码来源:__main__.py

示例9: IPdbKernel

class IPdbKernel(Kernel):
    implementation = 'IPdbKernel'
    implementation_version = '0.1'
    language = 'IPdb'
    language_version = '0.1'
    language_info = {'mimetype': 'text/plain'}
    banner = "IPython debugger kernel"

    def __init__(self, **kwargs):
        Kernel.__init__(self, **kwargs)

        # Instantiate IPython.core.debugger.Pdb here, pass it a phony 
        # stdout that provides a dummy flush() method and a write() method
        # that internally sends data using a function so that it can
        # be initialized to use self.send_response()
        write_func = lambda s: self.send_response(self.iopub_socket,
                                                  'stream',
                                                  {'name': 'stdout',
                                                   'text': s})
        sys.excepthook = functools.partial(BdbQuit_excepthook,
                                           excepthook=sys.excepthook)
        self.debugger = Pdb(stdout=PhonyStdout(write_func))
        self.debugger.set_trace(sys._getframe().f_back)

    def do_execute(self, code, silent, store_history=True,
                   user_expressions=None, allow_stdin=False):
        if not code.strip():
            return {'status': 'ok', 'execution_count': self.execution_count,
                    'payload': [], 'user_expressions': {}}

        # Process command:
        line = self.debugger.precmd(code)
        stop = self.debugger.onecmd(line)
        stop = self.debugger.postcmd(stop, line)
        if stop:
            self.debugger.postloop()

        return {'status': 'ok', 'execution_count': self.execution_count,
                'payload': [], 'user_expression': {}}

    def do_complete(self, code, cursor_pos):
        code = code[:cursor_pos]

        default = {'matches': [], 'cursor_start': 0,
                   'cursor_end': cursor_pos, 'metadata': dict(),
                   'status': 'ok'}

        if not code or code[-1] == ' ':
            return default

        # Run Pdb.completenames on code, extend matches with results:
        matches = self.debugger.completenames(code)

        if not matches:
            return default

        return {'matches': sorted(matches), 'cursor_start': cursor_pos-len(code),
                'cursor_end': cursor_pos, 'metadata': dict(),
                'status': 'ok'}
开发者ID:lebedov,项目名称:ipdbkernel,代码行数:59,代码来源:ipdbkernel.py

示例10: do_list_relative

    def do_list_relative(self, arg):
        try:
            relative_amount = int(arg)
        except:
            try:
                relative_amount = eval(arg, self.curframe.f_globals, self.curframe.f_locals) or 5
                if isinstance(relative_amount, tuple):
                    return Pdb.do_list(self, arg)
            except:
                relative_amount = 5

        top = max(1, self.curframe.f_lineno - relative_amount)
        bottom = min(len(open(self.curframe.f_code.co_filename, 'rb').readlines()),
                     self.curframe.f_lineno + relative_amount)
        return Pdb.do_list(self, '{0},{1}'.format(top, bottom))
开发者ID:amitassaraf,项目名称:pdbi,代码行数:15,代码来源:__main__.py

示例11: interactive_pdb

def interactive_pdb():
    """ inspect the traceback of the most recent exception. """
    import traceback
    from IPython.core.debugger import Pdb

    if last_tb is None:
        print("Nothing to debug.")
        return

    # print to stdout (sic!) what this pdb session is about
    msg = traceback.format_tb(last_tb)[-5:]
    print('Starting PDB session for:\n\n\033[94m%s\033[0m\n' % ''.join(msg))

    pdb = Pdb()
    pdb.reset()
    pdb.interaction(frame=None, traceback=last_tb)
开发者ID:Doik,项目名称:micropsi2,代码行数:16,代码来源:tools.py

示例12: main

def main():
    if not sys.argv[1:] or sys.argv[1] in ("--help", "-h"):
        print "usage: ipdb.py scriptfile [arg] ..."
        sys.exit(2)

    mainpyfile = sys.argv[1]     # Get script filename
    if not os.path.exists(mainpyfile):
        print 'Error:', mainpyfile, 'does not exist'
        sys.exit(1)

    del sys.argv[0]         # Hide "pdb.py" from argument list

    # Replace pdb's dir with script's dir in front of module search path.
    sys.path[0] = os.path.dirname(mainpyfile)

    # Note on saving/restoring sys.argv: it's a good idea when sys.argv was
    # modified by the script being debugged. It's a bad idea when it was
    # changed by the user from the command line. There is a "restart" command
    # which allows explicit specification of command line arguments.
    pdb = Pdb(def_colors)
    while 1:
        try:
            pdb._runscript(mainpyfile)
            if pdb._user_requested_quit:
                break
            print "The program finished and will be restarted"
        except Restart:
            print "Restarting", mainpyfile, "with arguments:"
            print "\t" + " ".join(sys.argv[1:])
        except SystemExit:
            # In most cases SystemExit does not warrant a post-mortem session.
            print "The program exited via sys.exit(). Exit status: ",
            print sys.exc_info()[1]
        except:
            traceback.print_exc()
            print "Uncaught exception. Entering post mortem debugging"
            print "Running 'cont' or 'step' will restart the program"
            t = sys.exc_info()[2]
            pdb.interaction(None, t)
            print "Post mortem debugger finished. The " + mainpyfile + \
                  " will be restarted"
开发者ID:DamianHeard,项目名称:ipdb,代码行数:41,代码来源:__main__.py

示例13: debug_shell

def debug_shell(user_ns, user_global_ns, traceback=None, execWrapper=None):
    ipshell = None
    if traceback:
        try:
            from IPython.core.debugger import Pdb
            from IPython.terminal.ipapp import TerminalIPythonApp
            ipapp = TerminalIPythonApp.instance()
            ipapp.interact = False  # Avoid output (banner, prints)
            ipapp.initialize(argv=[])
            def_colors = ipapp.shell.colors
            pdb_obj = Pdb(def_colors)
            pdb_obj.botframe = None  # not sure. exception otherwise at quit
            ipshell = lambda: pdb_obj.interaction(None, traceback=traceback)
        except Exception:
            pass
    if not ipshell:
        try:
            import IPython
            import IPython.terminal.embed
            class DummyMod(object): pass
            module = DummyMod()
            module.__dict__ = user_global_ns
            module.__name__ = "DummyMod"
            ipshell = IPython.terminal.embed.InteractiveShellEmbed(
                user_ns=user_ns, user_module=module)
        except Exception:
            pass
        else:
            if execWrapper:
                old = ipshell.run_code
                ipshell.run_code = lambda code: execWrapper(lambda: old(code))
    if ipshell:
        ipshell()
    else:
        if traceback:
            import pdb
            pdb.post_mortem(traceback)
        else:
            simple_debug_shell(user_global_ns, user_ns)
开发者ID:albertz,项目名称:PyCParser,代码行数:39,代码来源:better_exchook.py

示例14: main

def main():
  """ This is the main entry point for training and testing your classifier. """
  classifier = Classifier()
  experiment = Experiment(classifier)
  experiment.train('training')
  
  # Sanity check. Should get 100% on the training images. 
  report = experiment.test('training')
  report.print_summary()
  
  Pdb.set_trace()

  test_datasets = 'translations rotations scales noise occlusion distortion blurry_checkers'
  final_report = ClassificationReport("All Datasets")
  
  # Print the classification results of each test
  for dataset in test_datasets.split():
    report = experiment.test('testing/' + dataset)
    report.print_summary()
    #report.print_errors() # Uncomment this to print the error images for debugging. 
    final_report.extend(report)
  
  final_report.print_summary()
开发者ID:mrastegari,项目名称:Basic_Image_Classification,代码行数:23,代码来源:main.py

示例15: precmd

 def precmd(self, line):
     line = Pdb.precmd(self, line)
     if line:
         if line.endswith('??'):
             line = 'pinfo2 {0}'.format(line[:-2])
         elif line.endswith('?!'):
             line = 'psource {0}'.format(line[:-2])
         elif line.endswith('[email protected]'):
             line = 'pdef {0}'.format(line[:-2])
         elif line.endswith('?'):
             line = 'pinfo {0}'.format(line[:-1])
         elif line.startswith('!'):
             line = 'forcecommandmagic {0}'.format(line[1:])
     return line
开发者ID:amitassaraf,项目名称:pdbi,代码行数:14,代码来源:__main__.py


注:本文中的IPython.core.debugger.Pdb类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。