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


Python pdb.Pdb方法代码示例

本文整理汇总了Python中pdb.Pdb方法的典型用法代码示例。如果您正苦于以下问题:Python pdb.Pdb方法的具体用法?Python pdb.Pdb怎么用?Python pdb.Pdb使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pdb的用法示例。


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

示例1: set_trace

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import Pdb [as 别名]
def set_trace():
    """Call pdb.set_trace in the caller's frame.

    First restore sys.stdout and sys.stderr.  Note that the streams are
    NOT reset to whatever they were before the call once pdb is done!
    """
    import pdb
    for stream in 'stdout', 'stderr':
        output = getattr(sys, stream)
        orig_output = getattr(sys, '__%s__' % stream)
        if output != orig_output:
            # Flush the output before entering pdb
            if hasattr(output, 'getvalue'):
                orig_output.write(output.getvalue())
                orig_output.flush()
            setattr(sys, stream, orig_output)
    exc, tb = sys.exc_info()[1:]
    if tb:
        if isinstance(exc, AssertionError) and exc.args:
            # The traceback is not printed yet
            print_exc()
        pdb.post_mortem(tb)
    else:
        pdb.Pdb().set_trace(sys._getframe().f_back) 
开发者ID:OpenTrading,项目名称:OpenTrader,代码行数:26,代码来源:tools.py

示例2: help_hidden_frames

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import Pdb [as 别名]
def help_hidden_frames(self):
        print("""\
Some frames might be marked as "hidden": by default, hidden frames are not
shown in the stack trace, and cannot be reached using ``up`` and ``down``.
You can use ``hf_unhide`` to tell pdb++ to ignore the hidden status (i.e., to
treat hidden frames as normal ones), and ``hf_hide`` to hide them again.
``hf_list`` prints a list of hidden frames.

Frames can be marked as hidden in the following ways:

- by using the ``@pdb.hideframe`` function decorator

- by having ``__tracebackhide__=True`` in the locals or the globals of the
  function (this is used by pytest)

- by having ``__unittest=True`` in the globals of the function (this hides
  unittest internal stuff)

- by providing a list of skip patterns to the Pdb class constructor.  This
  list defaults to ``skip=["importlib._bootstrap"]``.

Note that the initial frame where ``set_trace`` was called from is not hidden,
except for when using the function decorator.
""", file=self.stdout) 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:26,代码来源:pdbpp.py

示例3: do_list

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import Pdb [as 别名]
def do_list(self, arg):
        """Enhance original do_list with highlighting."""
        if not (self.config.use_pygments is not False or self.config.highlight):
            return super(Pdb, self).do_list(arg)

        with self._patch_linecache_for_source_highlight():

            oldstdout = self.stdout
            self.stdout = StringIO()
            ret = super(Pdb, self).do_list(arg)
            orig_pdb_lines = self.stdout.getvalue().splitlines()
            self.stdout = oldstdout

        for line in self._format_color_prefixes(orig_pdb_lines):
            print(line, file=self.stdout)
        return ret 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:18,代码来源:pdbpp.py

示例4: set_trace

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import Pdb [as 别名]
def set_trace(self, frame=None):
        """Remember starting frame.

        This is used with pytest, which does not use pdb.set_trace().
        """
        if getattr(local, "_pdbpp_completing", False):
            # Handle set_trace being called during completion, e.g. with
            # fancycompleter's attr_matches.
            return
        if self.disabled:
            return

        if frame is None:
            frame = sys._getframe().f_back
        self._via_set_trace_frame = frame
        self._stopped_for_set_trace = False

        self.start_filename = frame.f_code.co_filename
        self.start_lineno = frame.f_lineno

        return super(Pdb, self).set_trace(frame) 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:23,代码来源:pdbpp.py

示例5: _remove_bdb_context

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import Pdb [as 别名]
def _remove_bdb_context(evalue):
        """Remove exception context from Pdb from the exception.

        E.g. "AttributeError: 'Pdb' object has no attribute 'do_foo'",
        when trying to look up commands (bpo-36494).
        Only done for Python 3+.
        """
        if not hasattr(evalue, "__context__"):
            return

        removed_bdb_context = evalue
        while removed_bdb_context.__context__:
            ctx = removed_bdb_context.__context__
            if (
                isinstance(ctx, AttributeError)
                and ctx.__traceback__.tb_frame.f_code.co_name == "onecmd"
            ):
                removed_bdb_context.__context__ = None
                break
            removed_bdb_context = removed_bdb_context.__context__


# simplified interface 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:25,代码来源:pdbpp.py

示例6: break_on_setattr

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import Pdb [as 别名]
def break_on_setattr(attrname, condition=always, Pdb=Pdb):
    def decorator(cls):
        old___setattr__ = cls.__setattr__

        @hideframe
        def __setattr__(self, attr, value):
            if attr == attrname and condition(self, value):
                frame = sys._getframe().f_back
                pdb_ = Pdb()
                pdb_.set_trace(frame)
                pdb_.stopframe = frame
                pdb_.interaction(frame, None)
            old___setattr__(self, attr, value)
        cls.__setattr__ = __setattr__
        return cls
    return decorator 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:18,代码来源:pdbpp.py

示例7: set_trace_via_module

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import Pdb [as 别名]
def set_trace_via_module(frame=None, cleanup=True, Pdb=PdbTest, **kwds):
    """set_trace helper that goes through pdb.set_trace.

    It injects Pdb into the globals of pdb.set_trace, to use the given frame.
    """
    if frame is None:
        frame = sys._getframe().f_back

    if cleanup:
        pdbpp.cleanup()

    class PdbForFrame(Pdb):
        def set_trace(self, _frame, *args, **kwargs):
            super(PdbForFrame, self).set_trace(frame, *args, **kwargs)

    newglobals = pdbpp.set_trace.__globals__.copy()
    newglobals['Pdb'] = PdbForFrame
    new_set_trace = pdbpp.rebind_globals(pdbpp.set_trace, newglobals)
    new_set_trace(**kwds) 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:21,代码来源:test_pdb.py

示例8: test_prompt_setter

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import Pdb [as 别名]
def test_prompt_setter():
    p = pdbpp.Pdb()
    assert p.prompt == "(Pdb++) "

    p.prompt = "(Pdb)"
    assert p.prompt == "(Pdb++)"
    p.prompt = "ipdb> "
    assert p.prompt == "ipdb++> "
    p.prompt = "custom"
    assert p.prompt == "custom++"
    p.prompt = "custom "
    assert p.prompt == "custom++ "
    p.prompt = "custom :"
    assert p.prompt == "custom++ :"
    p.prompt = "custom  "
    assert p.prompt == "custom++  "
    p.prompt = ""
    assert p.prompt == ""
    # Not changed (also used in tests).
    p.prompt = "# "
    assert p.prompt == "# "
    # Can be forced.
    p._prompt = "custom"
    assert p.prompt == "custom" 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:26,代码来源:test_pdb.py

示例9: test_config_pygments_deprecated_use_terminal256formatter

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import Pdb [as 别名]
def test_config_pygments_deprecated_use_terminal256formatter(monkeypatch):
    import pygments.formatters

    monkeypatch.setenv("TERM", "xterm-256color")

    class Config(DefaultConfig):
        use_terminal256formatter = False
    assert isinstance(
        Pdb(Config=Config)._get_pygments_formatter(),
        pygments.formatters.TerminalFormatter
    )

    class Config(DefaultConfig):
        use_terminal256formatter = True
    assert isinstance(
        Pdb(Config=Config)._get_pygments_formatter(),
        pygments.formatters.Terminal256Formatter
    ) 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:20,代码来源:test_pdb.py

示例10: test_break_on_setattr

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import Pdb [as 别名]
def test_break_on_setattr():
    # we don't use a class decorator to keep 2.5 compatibility
    class Foo(object):
        pass
    Foo = pdbpp.break_on_setattr('x', Pdb=PdbTest)(Foo)

    def fn():
        obj = Foo()
        obj.x = 0
        return obj.x

    check(fn, """
[NUM] > .*fn()
-> obj.x = 0
   5 frames hidden .*
# hasattr(obj, 'x')
False
# n
[NUM] > .*fn()
-> return obj.x
   5 frames hidden .*
# p obj.x
0
# c
""") 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:27,代码来源:test_pdb.py

示例11: test_handles_set_trace_in_config

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import Pdb [as 别名]
def test_handles_set_trace_in_config(tmpdir):
    """Should not cause a RecursionError."""
    def fn():
        class Config(ConfigTest):
            def __init__(self, *args, **kwargs):
                print("Config.__init__")
                # Becomes a no-op.
                set_trace(Config=Config)
                print("after_set_trace")

        set_trace(Config=Config)

    check(fn, r"""
Config.__init__
pdb\+\+: using pdb.Pdb for recursive set_trace.
> .*__init__()
-> print("after_set_trace")
(Pdb) c
after_set_trace
--Return--
[NUM] > .*fn()->None
-> set_trace(Config=Config)
   5 frames hidden .*
# c
""") 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:27,代码来源:test_pdb.py

示例12: _exec_main

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import Pdb [as 别名]
def _exec_main(parser, values):
    sconsflags = os.environ.get('SCONSFLAGS', '')
    all_args = sconsflags.split() + sys.argv[1:]

    options, args = parser.parse_args(all_args, values)

    if isinstance(options.debug, list) and "pdb" in options.debug:
        import pdb
        pdb.Pdb().runcall(_main, parser)
    elif options.profile_file:
        # compat layer imports "cProfile" for us if it's available.
        from profile import Profile

        prof = Profile()
        try:
            prof.runcall(_main, parser)
        finally:
            prof.dump_stats(options.profile_file)
    else:
        _main(parser) 
开发者ID:Autodesk,项目名称:arnold-usd,代码行数:22,代码来源:Main.py

示例13: __init__

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import Pdb [as 别名]
def __init__(self, out):
        self.__out = out
        pdb.Pdb.__init__(self) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:5,代码来源:doctest_driver.py

示例14: trace_dispatch

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import Pdb [as 别名]
def trace_dispatch(self, *args):
        save_stdout = sys.stdout
        sys.stdout = self.__out
        pdb.Pdb.trace_dispatch(self, *args)
        sys.stdout = save_stdout 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:7,代码来源:doctest_driver.py

示例15: _debug_recipe

# 需要导入模块: import pdb [as 别名]
# 或者: from pdb import Pdb [as 别名]
def _debug_recipe(recipe_deps, recipe, test_data):
  """Debugs the given recipe + test case.

  Args:

    * recipe_deps (RecipeDeps)
    * recipe (Recipe)
    * test_data (TestData)
  """
  debugger = pdb.Pdb()
  for func in [recipe.global_symbols['RunSteps']]:
    debugger.set_break(
        func.func_code.co_filename,
        func.func_code.co_firstlineno,
        funcname=func.func_code.co_name)

  try:
    def dispatch_thunk(frame, event, arg):
      """Triggers 'continue' command when debugger starts."""
      val = debugger.trace_dispatch(frame, event, arg)
      debugger.set_continue()
      sys.settrace(debugger.trace_dispatch)
      return val
    debugger.reset()
    sys.settrace(dispatch_thunk)
    try:
      execute_test_case(recipe_deps, recipe.name, test_data)
    finally:
      debugger.quitting = 1
      sys.settrace(None)
  except bdb.BdbQuit:
    pass
  except Exception:  # pylint: disable=broad-except
    traceback.print_exc()
    print 'Uncaught exception. Entering post mortem debugging'
    print 'Running \'cont\' or \'step\' will restart the program'
    tback = sys.exc_info()[2]
    debugger.interaction(None, tback) 
开发者ID:luci,项目名称:recipes-py,代码行数:40,代码来源:debug.py


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