Feature Request: Break and Debug where Error Occured

1,913 views
Skip to first unread message

Laurence

unread,
Jan 26, 2012, 11:08:34 PM1/26/12
to spyder
Hi,

First - for the record I think Spyder is fantastic, an easy to use and
powerful IDE for Python. I use it all the time.

One feature which I think would add value (apoligies if it exists and
I have simply not found it) is to have auto-debug when a program
breaks. i.e. If an error occurs in a function, for the debugger to
come on within the context of the function so the user can immediately
understand what is going on.

For instance:

function fred(a):
b = a-2
return 2/b

fred(2)

This would return an error (division by zero). May be (in a more
complicated example) harder to debug - especially if fred was called
many times before it was called and had an error. But if it could
automatically break and open a debugger in the context of fred then
the user could look at the value of b and understand the error.

Thanks,

Laurence

Steve

unread,
Feb 3, 2012, 6:28:40 PM2/3/12
to spyder
If you execute your code in the debugger (Ctrl+F5) you will be sitting
in the debugger in the console window after the exception occurs. At
this point you can use the pdb interface inspect variables and such.

You can learn more about the python debugger by doing some reading
here: http://pythonconquerstheuniverse.wordpress.com/2009/09/10/debugging-in-python/

I typically do most active development using the debugger. In 2.2 it
should be made much more integrated and polished up.


I do think it would be slick if there was a way to fire up pdb and do
some post mortem debugging even if you weren't running within pdb in
the first place, but I'm not sure if this is possible. I'd definitely
+1 the addition of this feature.

Steve

unread,
Feb 3, 2012, 6:29:51 PM2/3/12
to spyder
I should also mention that you have to use pdb commands to actually
start the execution, otherwise it will just sit at the pdb prompt
doing nothing.

c for continue will start execution. You can read on further pdb
commands in he link I pasted above.

On Feb 3, 5:28 pm, Steve <steve.f.thomp...@gmail.com> wrote:
> If you execute your code in the debugger (Ctrl+F5) you will be sitting
> in the debugger in the console window after the exception occurs.  At
> this point you can use the pdb interface inspect variables and such.
>
> You can learn more about the python debugger by doing some reading
> here:http://pythonconquerstheuniverse.wordpress.com/2009/09/10/debugging-i...

Ryan Clary

unread,
Feb 3, 2012, 6:42:22 PM2/3/12
to spyd...@googlegroups.com
I'd add that if you use the ipython console you can turn on automatic pdb calling. Typing pdb at the prompt will toggle automatic pdb calling. With this feature turned on, you can execute code normally (f5) and pdb is called automatically if an exception occurs, placing the prompt at the location of the exception.

Ryan Clary

> --
> You received this message because you are subscribed to the Google Groups "spyder" group.
> To post to this group, send email to spyd...@googlegroups.com.
> To unsubscribe from this group, send email to spyderlib+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/spyderlib?hl=en.
>

Steve

unread,
Feb 7, 2012, 2:05:46 PM2/7/12
to spyder
Thanks for the tip Ryan. I'm going to check out ipython for this
feature.

On Feb 3, 5:42 pm, Ryan Clary <mrcl...@gmail.com> wrote:
> I'd add that if you use the ipython console you can turn on automatic pdb calling. Typing pdb at the prompt will toggle automatic pdb calling. With this feature turned on, you can execute code normally (f5) and pdb is called automatically if an exception occurs, placing the prompt at the location of the exception.
>
> Ryan Clary
>
> On Feb 3, 2012, at 3:28 PM, Steve wrote:
>
>
>
>
>
>
>
> > If you execute your code in the debugger (Ctrl+F5) you will be sitting
> > in the debugger in the console window after the exception occurs.  At
> > this point you can use the pdb interface inspect variables and such.
>
> > You can learn more about the python debugger by doing some reading
> > here:http://pythonconquerstheuniverse.wordpress.com/2009/09/10/debugging-i...

Laurence

unread,
Feb 7, 2012, 4:49:32 PM2/7/12
to spyder
Thanks for all the responses, Steve and Ryan, much appreciated.

Between them all (including an email from Steve), we have a good set.
I have just been experimenting with:

1. Typing pdb to toggle on the automatic breaking into the debugger.
2. Using the Up and Down commands to move up and down the context
between calling functions.

I tried a simple test:

def fred():
aa = 1
fred1()
return

def fred1():
bb = 1
fred2()
return

def fred2():
cc = 1
print 1/0
return


fred()

The program broke at 1/0, and then went into pdb as required. Using
the Up and Down commands it successfully moved context between fred2,
fred1 and fred (and back down again). I was able to verify this by
looking at values of cc, bb and aa. This is great - thanks all for
some really good tips.

Laurence

On Feb 4, 10:42 am, Ryan Clary <mrcl...@gmail.com> wrote:
> I'd add that if you use the ipython console you can turn on automatic pdb calling. Typing pdb at the prompt will toggle automatic pdb calling. With this feature turned on, you can execute code normally (f5) and pdb is called automatically if an exception occurs, placing the prompt at the location of the exception.
>
> Ryan Clary
>
> On Feb 3, 2012, at 3:28 PM, Steve wrote:
>
>
>
> > If you execute your code in the debugger (Ctrl+F5) you will be sitting
> > in the debugger in the console window after the exception occurs.  At
> > this point you can use the pdb interface inspect variables and such.
>
> > You can learn more about the python debugger by doing some reading
> > here:http://pythonconquerstheuniverse.wordpress.com/2009/09/10/debugging-i...
> > For more options, visit this group athttp://groups.google.com/group/spyderlib?hl=en.- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages