Skip to content

Commit

Permalink
Fix up some more of the interrupt framework
Browse files Browse the repository at this point in the history
This (partially) fixes inducer#42, and also improves work on inducer#31.

Now, interrupting with Control-C works when the debugging is started with
set_trace().

The SIGINT handler is enabled via the public function
pudb.set_interrupt_handler.  If you want to be able to enter PuDB from within
your application, just call this function.  By default, it uses SIGINT (i.e.,
Control-C), but you can change it to use a different signal if that one
interferes.

There is still one major issue, which is that when you break in the middle of
an atomic operation, it goes to bdb. After pressing `n` several times you get
to your code, though.
  • Loading branch information
asmeurer committed Mar 12, 2013
1 parent 8911613 commit ce06073
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 12 additions & 0 deletions pudb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,22 @@ def set_trace():
import sys
dbg = _get_debugger()

set_interrupt_handler()
dbg.set_trace(sys._getframe().f_back)


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

def set_interrupt_handler(interrupt_signal=None):
"""
Set up an interrupt handler, to activate PuDB when Python receives the
signal `interrupt_signal`. By default it is SIGINT (i.e., Control-C).
"""
import signal
interrupt_signal = interrupt_signal or signal.SIGINT
signal.signal(interrupt_signal, _interrupt_handler)

def post_mortem(exc_info=None):
if exc_info is None:
Expand Down
8 changes: 2 additions & 6 deletions pudb/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import urwid
import bdb
import sys
import signal

from pudb.settings import load_config, save_config
CONFIG = load_config()
Expand All @@ -30,10 +29,6 @@ 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 @@ -317,7 +312,8 @@ def _runscript(self, filename):
statement = 'execfile( "%s")' % filename

# Set up an interrupt handler
signal.signal(signal.SIGINT, _interrupt_handler)
from pudb import set_interrupt_handler
set_interrupt_handler()

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

Expand Down

0 comments on commit ce06073

Please sign in to comment.