Important
This documentation covers IPython versions 6.0 and higher. Beginning with version 6.0, IPython stopped supporting compatibility with Python versions lower than 3.3 including all versions of Python 2.7.
If you are looking for an IPython version compatible with Python 2.7, please use the IPython 5.x LTS release and refer to its documentation (LTS is the long term support release).
Module: core.debugger
¶
Pdb debugger class.
Modified from the standard pdb.Pdb class to avoid including readline, so that the command line completion of other programs which include this isn’t damaged.
In the future, this class will be expanded with improvements over the standard pdb.
The code in this file is mainly lifted out of cmd.py in Python 2.2, with minor changes. Licensing should therefore be under the standard Python terms. For details on the PSF (Python Software Foundation) standard license, see:
https://docs.python.org/2/license.html
3 Classes¶
-
class
IPython.core.debugger.
Tracer
(colors=None)¶ Bases:
object
DEPRECATED
Class for local debugging, similar to pdb.set_trace.
Instances of this class, when called, behave like pdb.set_trace, but providing IPython’s enhanced capabilities.
This is implemented as a class which must be initialized in your own code and not as a standalone function because we need to detect at runtime whether IPython is already active or not. That detection is done in the constructor, ensuring that this code plays nicely with a running IPython, while functioning acceptably (though with limitations) if outside of it.
-
__init__
(colors=None)¶ DEPRECATED
Create a local debugger instance.
- Parameters
colors (str, optional) – The name of the color scheme to use, it must be one of IPython’s valid color schemes. If not given, the function will default to the current IPython scheme when running inside IPython, and to ‘NoColor’ otherwise.
Examples
from IPython.core.debugger import Tracer; debug_here = Tracer()
Later in your code:
debug_here() # -> will open up the debugger at that point.
Once the debugger activates, you can use all of its regular commands to step through code, set breakpoints, etc. See the pdb documentation from the Python standard library for usage details.
-
-
class
IPython.core.debugger.
Pdb
(color_scheme=None, completekey=None, stdin=None, stdout=None, context=5, **kwargs)¶ Bases:
pdb.Pdb
Modified Pdb class, does not load readline.
for a standalone version that uses prompt_toolkit, see
IPython.terminal.debugger.TerminalPdb
andIPython.terminal.debugger.set_trace()
-
__init__
(color_scheme=None, completekey=None, stdin=None, stdout=None, context=5, **kwargs)¶ Create a new IPython debugger.
- Parameters
color_scheme – Deprecated, do not use.
completekey – Passed to pdb.Pdb.
stdin – Passed to pdb.Pdb.
stdout – Passed to pdb.Pdb.
context – Number of lines of source code context to show when displaying stacktrace information.
kwargs – Passed to pdb.Pdb. The possibilities are python version dependent, see the python docs for more info.
-
do_d
(arg)¶ d(own) [count] Move the current frame count (default one) levels down in the stack trace (to a newer frame).
Will skip hidden frames.
-
do_debug
(arg)¶ debug code Enter a recursive debugger that steps through the code argument (which is an arbitrary expression or statement to be executed in the current environment).
-
do_down
(arg)¶ d(own) [count] Move the current frame count (default one) levels down in the stack trace (to a newer frame).
Will skip hidden frames.
-
do_l
(arg)¶ Print lines of code from the current stack frame
-
do_list
(arg)¶ Print lines of code from the current stack frame
-
do_ll
(arg)¶ Print lines of code from the current stack frame.
Shows more lines than ‘list’ does.
-
do_longlist
(arg)¶ Print lines of code from the current stack frame.
Shows more lines than ‘list’ does.
-
do_pdef
(arg)¶ Print the call signature for any callable object.
The debugger interface to %pdef
-
do_pdoc
(arg)¶ Print the docstring for an object.
The debugger interface to %pdoc.
-
do_pfile
(arg)¶ Print (or run through pager) the file where an object is defined.
The debugger interface to %pfile.
-
do_pinfo
(arg)¶ Provide detailed information about an object.
The debugger interface to %pinfo, i.e., obj?.
-
do_pinfo2
(arg)¶ Provide extra detailed information about an object.
The debugger interface to %pinfo2, i.e., obj??.
-
do_psource
(arg)¶ Print (or run through pager) the source code for an object.
-
do_q
(**kw)¶ q(uit) exit Quit from the debugger. The program being executed is aborted.
-
do_quit
(**kw)¶ q(uit) exit Quit from the debugger. The program being executed is aborted.
Change whether or not we should skip frames with the __tracebackhide__ attribute.
-
do_u
(arg)¶ u(p) [count] Move the current frame count (default one) levels up in the stack trace (to an older frame).
Will skip hidden frames.
-
do_up
(arg)¶ u(p) [count] Move the current frame count (default one) levels up in the stack trace (to an older frame).
Will skip hidden frames.
-
do_w
(arg)¶ w(here) Print a stack trace, with the most recent frame at the bottom. An arrow indicates the “current frame”, which determines the context of most commands. ‘bt’ is an alias for this command.
Take a number as argument as an (optional) number of context line to print
-
do_where
(arg)¶ w(here) Print a stack trace, with the most recent frame at the bottom. An arrow indicates the “current frame”, which determines the context of most commands. ‘bt’ is an alias for this command.
Take a number as argument as an (optional) number of context line to print
-
format_stack_entry
(frame_lineno, lprefix=': ', context=None)¶ Return a string with information about a stack entry.
The stack entry frame_lineno is a (frame, lineno) tuple. The return string contains the canonical filename, the function name or ‘<lambda>’, the input arguments, the return value, and the line of code (if it exists).
Given an index in the stack return wether it should be skipped.
This is used in up/down and where to skip frames.
-
new_do_restart
(arg)¶ Restart command. In the context of ipython this is exactly the same thing as ‘quit’.
-
print_list_lines
(filename, first, last)¶ The printing (as opposed to the parsing part of a ‘list’ command.
-
set_colors
(scheme)¶ Shorthand access to the color table scheme selector method.
-
set_trace
(frame=None)¶ Start debugging from frame.
If frame is not specified, debugging starts from caller’s frame.
-
stop_here
(frame)¶ Check if pdb should stop here
-
-
class
IPython.core.debugger.
InterruptiblePdb
(color_scheme=None, completekey=None, stdin=None, stdout=None, context=5, **kwargs)¶ Bases:
IPython.core.debugger.Pdb
Version of debugger where KeyboardInterrupt exits the debugger altogether.
-
cmdloop
()¶ Wrap cmdloop() such that KeyboardInterrupt stops the debugger.
-
6 Functions¶
-
IPython.core.debugger.
make_arrow
(pad)¶ generate the leading arrow in front of traceback or debugger
-
IPython.core.debugger.
BdbQuit_excepthook
(et, ev, tb, excepthook=None)¶ Exception hook which handles
BdbQuit
exceptions.All other exceptions are processed using the
excepthook
parameter.
-
IPython.core.debugger.
BdbQuit_IPython_excepthook
(self, et, ev, tb, tb_offset=None)¶
-
IPython.core.debugger.
strip_indentation
(multiline_string)¶
-
IPython.core.debugger.
decorate_fn_with_doc
(new_fn, old_fn, additional_text='')¶ Make new_fn have old_fn’s doc string. This is particularly useful for the
do_...
commands that hook into the help system. Adapted from from a comp.lang.python posting by Duncan Booth.
-
IPython.core.debugger.
set_trace
(frame=None)¶ Start debugging from
frame
.If frame is not specified, debugging starts from caller’s frame.