當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。