本文整理汇总了Python中IPython.core.debugger.Pdb方法的典型用法代码示例。如果您正苦于以下问题:Python debugger.Pdb方法的具体用法?Python debugger.Pdb怎么用?Python debugger.Pdb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPython.core.debugger
的用法示例。
在下文中一共展示了debugger.Pdb方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ipdb_magics2
# 需要导入模块: from IPython.core import debugger [as 别名]
# 或者: from IPython.core.debugger import Pdb [as 别名]
def test_ipdb_magics2():
'''Test ipdb with a very short function.
>>> def bar():
... pass
Run ipdb.
>>> with PdbTestInput([
... 'continue',
... ]):
... debugger.Pdb().runcall(bar)
> <doctest ...>(2)bar()
1 def bar():
----> 2 pass
<BLANKLINE>
ipdb> continue
'''
示例2: __init__
# 需要导入模块: from IPython.core import debugger [as 别名]
# 或者: from IPython.core.debugger import Pdb [as 别名]
def __init__(self, color_scheme='NoColor', call_pdb=False, ostream=None):
# Whether to call the interactive pdb debugger after printing
# tracebacks or not
self.call_pdb = call_pdb
# Output stream to write to. Note that we store the original value in
# a private attribute and then make the public ostream a property, so
# that we can delay accessing io.stdout until runtime. The way
# things are written now, the io.stdout object is dynamically managed
# so a reference to it should NEVER be stored statically. This
# property approach confines this detail to a single location, and all
# subclasses can simply access self.ostream for writing.
self._ostream = ostream
# Create color table
self.color_scheme_table = exception_colors()
self.set_colors(color_scheme)
self.old_scheme = color_scheme # save initial value for toggles
if call_pdb:
self.pdb = debugger.Pdb(self.color_scheme_table.active_scheme_name)
else:
self.pdb = None
示例3: debug
# 需要导入模块: from IPython.core import debugger [as 别名]
# 或者: from IPython.core.debugger import Pdb [as 别名]
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)
示例4: set_trace
# 需要导入模块: from IPython.core import debugger [as 别名]
# 或者: from IPython.core.debugger import Pdb [as 别名]
def set_trace():
from IPython.core.debugger import Pdb
try:
Pdb(color_scheme='Linux').set_trace(sys._getframe().f_back)
except Exception:
from pdb import Pdb as OldPdb
OldPdb().set_trace(sys._getframe().f_back)
# -----------------------------------------------------------------------------
# contextmanager to ensure the file cleanup
示例5: with_fake_debugger
# 需要导入模块: from IPython.core import debugger [as 别名]
# 或者: from IPython.core.debugger import Pdb [as 别名]
def with_fake_debugger(func):
@functools.wraps(func)
def wrapper(*args, **kwds):
with tt.monkeypatch(debugger.Pdb, 'run', staticmethod(eval)):
return func(*args, **kwds)
return wrapper
示例6: set_trace
# 需要导入模块: from IPython.core import debugger [as 别名]
# 或者: from IPython.core.debugger import Pdb [as 别名]
def set_trace():
from IPython.core.debugger import Pdb
try:
Pdb(color_scheme='Linux').set_trace(sys._getframe().f_back)
except:
from pdb import Pdb as OldPdb
OldPdb().set_trace(sys._getframe().f_back)
#------------------------------------------------------------------------------
# contextmanager to ensure the file cleanup
示例7: set_trace
# 需要导入模块: from IPython.core import debugger [as 别名]
# 或者: from IPython.core.debugger import Pdb [as 别名]
def set_trace(frame=None):
update_stdout()
wrap_sys_excepthook()
if frame is None:
frame = sys._getframe().f_back
Pdb(def_colors).set_trace(frame)
示例8: post_mortem
# 需要导入模块: from IPython.core import debugger [as 别名]
# 或者: from IPython.core.debugger import Pdb [as 别名]
def post_mortem(tb):
update_stdout()
wrap_sys_excepthook()
p = Pdb(def_colors)
p.reset()
if tb is None:
return
p.interaction(None, tb)
示例9: run
# 需要导入模块: from IPython.core import debugger [as 别名]
# 或者: from IPython.core.debugger import Pdb [as 别名]
def run(statement, globals=None, locals=None):
Pdb(def_colors).run(statement, globals, locals)
示例10: runcall
# 需要导入模块: from IPython.core import debugger [as 别名]
# 或者: from IPython.core.debugger import Pdb [as 别名]
def runcall(*args, **kwargs):
return Pdb(def_colors).runcall(*args, **kwargs)
示例11: runeval
# 需要导入模块: from IPython.core import debugger [as 别名]
# 或者: from IPython.core.debugger import Pdb [as 别名]
def runeval(expression, globals=None, locals=None):
return Pdb(def_colors).runeval(expression, globals, locals)
示例12: set_trace
# 需要导入模块: from IPython.core import debugger [as 别名]
# 或者: from IPython.core.debugger import Pdb [as 别名]
def set_trace():
from IPython.core.debugger import Pdb
try:
Pdb(color_scheme='Linux').set_trace(sys._getframe().f_back)
except:
from pdb import Pdb as OldPdb
OldPdb().set_trace(sys._getframe().f_back)
# -----------------------------------------------------------------------------
# contextmanager to ensure the file cleanup
示例13: test_ipdb_magics
# 需要导入模块: from IPython.core import debugger [as 别名]
# 或者: from IPython.core.debugger import Pdb [as 别名]
def test_ipdb_magics():
'''Test calling some IPython magics from ipdb.
First, set up some test functions and classes which we can inspect.
>>> class ExampleClass(object):
... """Docstring for ExampleClass."""
... def __init__(self):
... """Docstring for ExampleClass.__init__"""
... pass
... def __str__(self):
... return "ExampleClass()"
>>> def example_function(x, y, z="hello"):
... """Docstring for example_function."""
... pass
Create a function which triggers ipdb.
>>> def trigger_ipdb():
... a = ExampleClass()
... debugger.Pdb().set_trace()
>>> with PdbTestInput([
... 'pdef example_function',
... 'pdoc ExampleClass',
... 'pinfo a',
... 'continue',
... ]):
... trigger_ipdb()
--Return--
None
> <doctest ...>(3)trigger_ipdb()
1 def trigger_ipdb():
2 a = ExampleClass()
----> 3 debugger.Pdb().set_trace()
<BLANKLINE>
ipdb> pdef example_function
example_function(x, y, z='hello')
ipdb> pdoc ExampleClass
Class Docstring:
Docstring for ExampleClass.
Constructor Docstring:
Docstring for ExampleClass.__init__
ipdb> pinfo a
Type: ExampleClass
String Form:ExampleClass()
Namespace: Locals
File: ...
Docstring: Docstring for ExampleClass.
Constructor Docstring:Docstring for ExampleClass.__init__
ipdb> continue
'''
示例14: debugger
# 需要导入模块: from IPython.core import debugger [as 别名]
# 或者: from IPython.core.debugger import Pdb [as 别名]
def debugger(self,force=False):
"""Call up the pdb debugger if desired, always clean up the tb
reference.
Keywords:
- force(False): by default, this routine checks the instance call_pdb
flag and does not actually invoke the debugger if the flag is false.
The 'force' option forces the debugger to activate even if the flag
is false.
If the call_pdb flag is set, the pdb interactive debugger is
invoked. In all cases, the self.tb reference to the current traceback
is deleted to prevent lingering references which hamper memory
management.
Note that each call to pdb() does an 'import readline', so if your app
requires a special setup for the readline completers, you'll have to
fix that by hand after invoking the exception handler."""
if force or self.call_pdb:
if self.pdb is None:
self.pdb = debugger.Pdb(
self.color_scheme_table.active_scheme_name)
# the system displayhook may have changed, restore the original
# for pdb
display_trap = DisplayTrap(hook=sys.__displayhook__)
with display_trap:
self.pdb.reset()
# Find the right frame so we don't pop up inside ipython itself
if hasattr(self,'tb') and self.tb is not None:
etb = self.tb
else:
etb = self.tb = sys.last_traceback
while self.tb is not None and self.tb.tb_next is not None:
self.tb = self.tb.tb_next
if etb and etb.tb_next:
etb = etb.tb_next
self.pdb.botframe = etb.tb_frame
self.pdb.interaction(self.tb.tb_frame, self.tb)
if hasattr(self,'tb'):
del self.tb