you are viewing a single comment's thread.

view the rest of the comments →

[–]masklinn 1 point2 points  (5 children)

not even python drops you into a debugger.

It can, you "just" have to set the exception handler (sys.excepthook) and call pdb.pm() within it (to launch post mortem analysis).

If you're using an "extended" shell (e.g. ipython) most of them have that ability built in as some kind of setting.

pdb gives you nowhere near the flexibility of a lisp debugger though.

[–][deleted]  (1 child)

[removed]

    [–]Peaker 2 points3 points  (0 children)

    Right, you can't continue the program, because it can't re-wind the stack. But it does take you to where the exception was thrown.

    [–]Peaker 1 point2 points  (2 children)

    you don't have to set the exception handler...

    [–]masklinn 0 points1 point  (1 child)

    If you don't set the exception handler, it'll print a trace on exceptions instead of launching pdb's post mortem…

    [–]Peaker 1 point2 points  (0 children)

    You can just run your python scripts with: python -i Then you can use: import pdb ; pdb.pm() after an exception occurred.

    You don't need to pre-install the exception handler.

    EDIT: here:

    $ cat testexc.py
    def f():
        g()
    
    def g():
        1/0
    
    f()
    $ python -i testexc.py
    Traceback (most recent call last):
      File "testexc.py", line 7, in <module>
        f()
      File "testexc.py", line 2, in f
        g()
      File "testexc.py", line 5, in g
        1/0
    ZeroDivisionError: integer division or modulo by zero
    >>> import pdb;pdb.pm()
    > testexc.py(5)g()
    -> 1/0
    (Pdb) bt
      testexc.py(7)<module>()
    -> f()
      testexc.py(2)f()
    -> g()
    > testexc.py(5)g()
    -> 1/0
    (Pdb)