Skip to content

Commit

Permalink
Enable Control-C to pause the debugger
Browse files Browse the repository at this point in the history
This fixes #42.  Now pressing Control-C while the script is running enters the
debugger in the line that was run (i.e., it does a set_trace()).

Note that this only works if the script was invoked from `pudb` or `python -m
pudb`.  If PuDB was started with `import pudb; pudb.set_trace()`, this does
not work.  But not that even without this patch, Control-C kills Python
entirely in that case (as opposed to entering post-mortem mode).
  • Loading branch information
asmeurer committed Mar 12, 2013
1 parent 7b35aed commit 8911613
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pudb/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import urwid
import bdb
import sys
import signal

from pudb.settings import load_config, save_config
CONFIG = load_config()
Expand All @@ -29,6 +30,10 @@ def newfunc(*fargs, **fkeywords):
newfunc.keywords = keywords
return newfunc

def _interrupt_handler(signum, frame):
from pudb import set_trace
set_trace()

HELP_TEXT = """\
Welcome to PuDB, the Python Urwid debugger.
-------------------------------------------
Expand Down Expand Up @@ -125,8 +130,6 @@ def newfunc(*fargs, **fkeywords):
OTHER DEALINGS IN THE SOFTWARE.
"""



# {{{ debugger interface

class Debugger(bdb.Bdb):
Expand Down Expand Up @@ -312,6 +315,10 @@ def _runscript(self, filename):
statement = 'exec(compile(open("%s").read(), "%s", "exec"))' % (filename, filename)
else:
statement = 'execfile( "%s")' % filename

# Set up an interrupt handler
signal.signal(signal.SIGINT, _interrupt_handler)

self.run(statement, globals=globals_, locals=locals_)

# }}}
Expand Down

0 comments on commit 8911613

Please sign in to comment.