Debugging

Some options are:

Run in ipython

As in:

In [1]: run mymodule.py
... (somecrash)
In [2]: %debug

Then diagnose, using the workspace that comes up, which has the context of the crash.

You can also do:

In [1] %pdb on
In [2]: run mymodule.py
... (somecrash)

At that point you will be automatically dropped into the the workspace in the context of the error. This is very similar to the matlab dbstop if error command.

See the ipython manual , and debugging in ipython for more detail.

Embed ipython in crashing code

Often it is not possible to run the code directly from ipython using the run command. For example, the code may be called from some other system such as sphinx. In that case you can embed. At the point that you want ipython to open with the context available for introspection, add:

from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed()
ipshell()

See embedding ipython for more detail.