Matt Joiner
Matt Joiner

Reputation: 118540

Using a debugger and curses at the same time?

I'm calling python -m pdb myapp.py, when an exception fires, and I'd normally be thrown back to the pdb interpreter to investigate the problem. However this exception is being thrown after I've called through curses.wrapper() and entered curses mode, rendering the pdb interpreter useless. How can I work around this?

Upvotes: 11

Views: 2569

Answers (3)

杨耀飞
杨耀飞

Reputation: 11

use pyclewn

you can use pyclewn with vim. or use pdb-clone,the core of pyclewn its good ,its like gdb ,can remote debug

Upvotes: 0

Noufal Ibrahim
Noufal Ibrahim

Reputation: 72755

James` answer is a good and I've upvoted it but I'd also consider trying to split the logic and presentation layers of my program. Keep the curses part a thin layer on top of a library and write a simple driver that invokes the correct routines to recreate the error. Then you can dive in and do what's necessary.

Another way I can think of is to create a function called debug or something that throws you back into the regular screen and invokes pdb. Then stick it just before the code that raises the exception and run your program. Something like

def debug(stdscr):
    curses.nocbreak()
    stdscr.keypad(0)
    curses.echo()
    curses.endwin()
    import pdb; pdb.set_trace()

Apparently, this is similar to what is done with the curses.wrapper function. It's mentioned briefly at http://www.amk.ca/python/howto/curses/.

Upvotes: 10

James Morris
James Morris

Reputation: 4935

Not being familiar with Python, this may not be exactly what you want. But apparently, winpdb can attach to a script - just like gdb can to a running process (IIUC).

http://winpdb.org/docs/launch-time/

Don't be mislead by the name, it is platform independent.

Upvotes: 6

Related Questions