Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interrupt (pause) running Python program in pdb?

In gdb, you can interrupt(pause) the program by C-c and resume.

Can you do this in pdb?

like image 202
eugene Avatar asked Apr 20 '12 03:04

eugene


People also ask

How do you set a breakpoint in Python pdb?

It's easy to set a breakpoint in Python code to i.e. inspect the contents of variables at a given line. Add import pdb; pdb. set_trace() at the corresponding line in the Python code and execute it. The execution will stop at the breakpoint.

How do you end a loop in pdb?

Once you get you pdb prompt . Just hit n (next) 10 times to exit the loop.

How do you stop pdb?

To start execution, you use the continue or c command. If the program executes successfully, you will be taken back to the (Pdb) prompt where you can restart the execution again. At this point, you can use quit / q or Ctrl+D to exit the debugger.


1 Answers

No, python2's pdb doesn't support this, but you add this code to your program as a workaround:

def debug_signal_handler(signal, frame):     import pdb     pdb.set_trace() import signal signal.signal(signal.SIGINT, debug_signal_handler) 

Related questions:

  • Showing the stack trace from a running Python application
  • enter pdb with kill signal
like image 132
JDiMatteo Avatar answered Sep 28 '22 03:09

JDiMatteo