31

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

Can you do this in pdb?

eugene
  • 39,839
  • 68
  • 255
  • 489

3 Answers3

26

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:

Community
  • 1
  • 1
JDiMatteo
  • 12,022
  • 5
  • 54
  • 65
8

Based on this bug report it might be fixed in Python 3.

In 2.x Ctrl-C will throw a KeyboardInterrupt, which is typically unhandled by the program, and will put the debugger into 'post-mortem' mode. You cannot continue where you left off.

I don't know if there's some other way to do what you are describing.

jwd
  • 10,837
  • 3
  • 43
  • 67
0

This now seems to be supported, based on what was predicted in jwd's answer.

With Python 3.8, hitting Ctrl+C pauses execution, after which you can step through code & navigate up/down the execution stack using the commands listed here:

How to step through Python code to help debug issues?

Oli
  • 41
  • 1
  • 4