Merge pull request #235 from asmeurer/set_continue
Add set_continue() function to __init__.py
This commit is contained in:
commit
c3ffcee021
24
README.rst
24
README.rst
@ -122,17 +122,25 @@ PuDB also has a `mailing list <http://lists.tiker.net/listinfo/pudb>`_ that
|
||||
you may use to submit patches and requests for help. You can also send a pull
|
||||
request to the `GitHub repository <https://github.com/inducer/pudb>`_
|
||||
|
||||
Attaching to Running Code
|
||||
-------------------------
|
||||
Starting the debugger without breaking
|
||||
--------------------------------------
|
||||
|
||||
An alternative to using ``set_trace`` is to use::
|
||||
To start the debugger without actually pausing use::
|
||||
|
||||
from pudb import set_interrupt_handler; set_interrupt_handler()
|
||||
from pudb import set_trace; set_trace(paused=False)
|
||||
|
||||
at the top of your code. This will set ``SIGINT`` (i.e., ``Ctrl-c``) to
|
||||
run ``set_trace``, so that typing ``Ctrl-c`` while your code is running
|
||||
will break the code and start debugging. See the docstring of
|
||||
``set_interrupt_handler`` for more information.
|
||||
at the top of your code. This will start the debugger without breaking, and
|
||||
run it until a predefined breakpoint is hit. You can also press ``b`` on a
|
||||
``set_trace`` call inside the debugger, and it will prevent it from stopping
|
||||
there.
|
||||
|
||||
Interrupt Handlers
|
||||
------------------
|
||||
|
||||
``set_trace`` sets ``SIGINT`` (i.e., ``Ctrl-c``) to run ``set_trace``, so that
|
||||
typing ``Ctrl-c`` while your code is running will break the code and start
|
||||
debugging. See the docstring of ``set_interrupt_handler`` for more
|
||||
information. Note that this only works in the main thread.
|
||||
|
||||
Programming PuDB
|
||||
----------------
|
||||
|
@ -23,6 +23,17 @@ class PudbShortcuts(object):
|
||||
dbg.set_trace(sys._getframe().f_back)
|
||||
|
||||
|
||||
@property
|
||||
def go(self):
|
||||
import sys
|
||||
dbg = _get_debugger()
|
||||
|
||||
import threading
|
||||
if isinstance(threading.current_thread(), threading._MainThread):
|
||||
set_interrupt_handler()
|
||||
dbg.set_trace(sys._getframe().f_back, paused=False)
|
||||
|
||||
|
||||
if PY3:
|
||||
import builtins
|
||||
builtins.__dict__["pu"] = PudbShortcuts()
|
||||
@ -151,15 +162,23 @@ def runcall(*args, **kwds):
|
||||
return _get_debugger().runcall(*args, **kwds)
|
||||
|
||||
|
||||
def set_trace():
|
||||
def set_trace(paused=True):
|
||||
"""
|
||||
Start the debugger
|
||||
|
||||
If paused=False (the default is True), the debugger will not stop here
|
||||
(same as immediately pressing 'c' to continue).
|
||||
"""
|
||||
import sys
|
||||
dbg = _get_debugger()
|
||||
|
||||
import threading
|
||||
if isinstance(threading.current_thread(), threading._MainThread):
|
||||
set_interrupt_handler()
|
||||
dbg.set_trace(sys._getframe().f_back)
|
||||
|
||||
dbg.set_trace(sys._getframe().f_back, paused=paused)
|
||||
|
||||
start = set_trace
|
||||
|
||||
def _interrupt_handler(signum, frame):
|
||||
from pudb import _get_debugger
|
||||
|
@ -194,7 +194,7 @@ class Debugger(bdb.Bdb):
|
||||
break
|
||||
frame = frame.f_back
|
||||
|
||||
def set_trace(self, frame=None, as_breakpoint=True):
|
||||
def set_trace(self, frame=None, as_breakpoint=None, paused=True):
|
||||
"""Start debugging from `frame`.
|
||||
|
||||
If frame is not specified, debugging starts from caller's frame.
|
||||
@ -202,7 +202,19 @@ class Debugger(bdb.Bdb):
|
||||
Unlike Bdb.set_trace(), this does not call self.reset(), which causes
|
||||
the debugger to enter bdb source code. This also implements treating
|
||||
set_trace() calls as breakpoints in the PuDB UI.
|
||||
|
||||
If as_breakpoint=True (the default), this call will be treated like a
|
||||
breakpoint in the UI (you can press 'b' on it to disable breaking
|
||||
here).
|
||||
|
||||
If paused=False, the debugger will not break here.
|
||||
"""
|
||||
if as_breakpoint is None:
|
||||
if not paused:
|
||||
as_breakpoint = False
|
||||
else:
|
||||
as_breakpoint = True
|
||||
|
||||
if frame is None:
|
||||
frame = thisframe = sys._getframe().f_back
|
||||
else:
|
||||
@ -225,7 +237,10 @@ class Debugger(bdb.Bdb):
|
||||
self.ui.set_source_code_provider(
|
||||
self.ui.source_code_provider, force_update=True)
|
||||
|
||||
self.set_step()
|
||||
if paused:
|
||||
self.set_step()
|
||||
else:
|
||||
self.set_continue()
|
||||
sys.settrace(self.trace_dispatch)
|
||||
else:
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user