breaking out to the debugger (other than x=1/0 !)

B

bdb112

After a while programming in python, I still don't know how to break
out to the debugger other than inserting an instruction to cause an
exception.
x=1/0

In IDL one woudl write

stop,'reason for stopping...'
at which point you can inspect locals (as in pdb) and continue (but
you can't with pdb if python stopped because of an exception)

I am using ipython -pylab -pdb (python 2.5,2.6)
Yes, I realise that I could start with the debugger, and set break
points, but that can be slower and sometimes cause problems, and I
like ipython's magic features.

Also, I don't know how to stop cleanly handing control back to ipython
inside a program - e.g. after printing help text.
 
D

Diez B. Roggisch

bdb112 said:
After a while programming in python, I still don't know how to break
out to the debugger other than inserting an instruction to cause an
exception.
x=1/0

In IDL one woudl write

stop,'reason for stopping...'
at which point you can inspect locals (as in pdb) and continue (but
you can't with pdb if python stopped because of an exception)

I am using ipython -pylab -pdb (python 2.5,2.6)
Yes, I realise that I could start with the debugger, and set break
points, but that can be slower and sometimes cause problems, and I
like ipython's magic features.

Also, I don't know how to stop cleanly handing control back to ipython
inside a program - e.g. after printing help text.

I use

import pdb; pdb.set_trace()

Of course that can't be deleted as breakpoint - but it suits me well.

Diez
 
B

bdb112

That's perfect - and removing the "breakpoint" is not an issue for me
as it is normally conditional on a debug level, which I can change
from pydb

if debuglvl>3:
import pydb
pydb.set_trace()
'in XXX: c to continue'

The text line is a useful prompt

(The example here is for pydb which works as well (and is more like
gdb).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top