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

Discussion in 'Python' started by bdb112, Oct 23, 2009.

  1. bdb112

    bdb112 Guest

    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.
    bdb112, Oct 23, 2009
    #1
    1. Advertising

  2. bdb112 wrote:

    > 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
    Diez B. Roggisch, Oct 23, 2009
    #2
    1. Advertising

  3. bdb112

    bdb112 Guest

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

    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).



    On Oct 23, 12:07 pm, "Diez B. Roggisch" <> wrote:
    > bdb112 wrote:
    > > 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
    bdb112, Oct 23, 2009
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Amy
    Replies:
    0
    Views:
    493
  2. Cesar
    Replies:
    0
    Views:
    328
    Cesar
    Oct 28, 2003
  3. Replies:
    0
    Views:
    482
  4. Robert Dodier
    Replies:
    1
    Views:
    439
    Jeff Higgins
    Apr 11, 2008
  5. bdb112
    Replies:
    0
    Views:
    181
    bdb112
    Oct 23, 2009
Loading...

Share This Page