joachim joachim - 1 month ago 41
Python Question

Exiting Python Debugger ipdb

I use ipdb fairly often in a way to just jump to a piece of code that is isolated i.e. it is hard to write a real script that uses it. Instead I write a minimal test case with mocking and jump into it.

Exemplary for the workflow:

def func():
import ipdb

def test_case():

Then, invoke

py.test -s -k test_case

Now, usually I just check one variable or two, and then want to quit. Change the code and do it over again.

How do I quit? The manual says
quits the debugger. It doesn't (really). You have to quit a few times before the debugger actually terminates. The same behavior for Ctrl-C and Ctrl-D (with the additional frustration that hitting Ctrl-D several times eventually quits the terminal, too).

Is there a smart way to force quit? Is this workflow even sensible? What is the standard way to do it?


I put the following in my .pdbrc

import os

alias kk os.system('kill -9 %d' % os.getpid())

kk kills the debugger and (the process that trigger the debugger).