how to halt python program after pdb.set_trace()
<p>When debugging scripts in Python (2.7, running on Linux) I occasionally inject pdb.set_trace() (note that I'm actually using ipdb), e.g.:</p>

<pre><code>import ipdb as pdb
try:
    do_something()
    # I'd like to look at some local variables before running do_something_dangerous()
    pdb.set_trace()
except:
    pass
do_something_dangerous()
</code></pre>

<p>I typically run my script from the shell, e.g.</p>

<pre><code>python my_script.py
</code></pre>

<p>Sometimes during my debugging session I realize that I don't want to run do_something_dangerous(). What's the easiest way to halt program execution so that do_something_dangerous() is not run and I can quit back to the shell?</p>

<p>As I understand it pressing ctrl-d (or issuing the debugger's quit command) will simply exit ipdb and the program will continue running (in my example above). Pressing ctrl-c seems to raise a KeyboardInterrupt but I've never understood the context in which it was raised.</p>

<p>I'm hoping for something like ctrl-q to simply take down the entire process, but I haven't been able to find anything.</p>

<p>I understand that my example is highly contrived, but my question is about how to abort execution from pdb when the code being debugged is set up to catch exceptions. It's not about how to restructure the above code so it works!</p>

<p>From the <a href="https://docs.python.org/3/library/pdb.html#pdbcommand-quit" rel="nofollow">module docs</a>:</p>

<blockquote>
  <p>q(uit)
  Quit from the debugger. The program being executed is aborted.</p>
</blockquote>

<p>Specifically, this will cause the next debugger function that gets called to raise a <a href="https://docs.python.org/3/library/bdb.html#bdb.BdbQuit" rel="nofollow"><code>BdbQuit</code></a> exception. </p>

python pdb ipdb