Permalink
Browse files

Implement and debug the programming interface to match pdb.

  • Loading branch information...
1 parent f6715a4 commit 97dfba7454653e22084cf78e8c90cb26b0923c23 @inducer inducer committed Jul 9, 2009
Showing with 54 additions and 12 deletions.
  1. +34 −12 pudb/__init__.py
  2. +7 −0 setup.py
  3. +5 −0 test/test-api.py
  4. +8 −0 test/test-postmortem.py
View
@@ -3,25 +3,47 @@
-CURRENT_DEBUGGER = [None]
-def set_trace():
- if CURRENT_DEBUGGER[0] is None:
+CURRENT_DEBUGGER = []
+def _get_debugger():
+ if not CURRENT_DEBUGGER:
from pudb.debugger import Debugger
dbg = Debugger()
- CURRENT_DEBUGGER[0] = dbg
+ CURRENT_DEBUGGER.append(dbg)
+ return dbg
+ else:
+ return CURRENT_DEBUGGER[0]
+
+
- import sys
- dbg.set_trace(sys._getframe().f_back)
+def run(statement, globals=None, locals=None):
+ _get_debugger().run(statement, globals, locals)
+def runeval(expression, globals=None, locals=None):
+ return _get_debugger().runeval(expression, globals, locals)
+
+def runcall(*args, **kwds):
+ return _get_debugger().runcall(*args, **kwds)
+
+def set_trace():
+ import sys
+ _get_debugger().set_trace(sys._getframe().f_back)
+
+
+
+
+def post_mortem(exc_info=None):
+ if exc_info is None:
+ import sys
+ exc_info = sys.exc_info()
+ tb = exc_info[2]
+ while tb.tb_next is not None:
+ tb = tb.tb_next
-def post_mortem(t):
- p = Debugger()
- p.reset()
- while t.tb_next is not None:
- t = t.tb_next
- p.interaction(t.tb_frame, t)
+ dbg = _get_debugger()
+ dbg.reset()
+ dbg.interaction(tb.tb_frame, exc_info)
View
@@ -70,6 +70,13 @@
python -m pudb.run my-script.py
+ Programming PuDB
+ ----------------
+
+ At the programming language level, PuDB displays the same interface
+ as Python's built-in `pdb module <http://docs.python.org/library/pdb.html>`_.
+ Just replace `pdb` with `pudb`.
+
License and Dependencies
------------------------
View
@@ -0,0 +1,5 @@
+def f():
+ fail
+
+from pudb import runcall
+runcall(f)
@@ -0,0 +1,8 @@
+def f():
+ fail
+
+try:
+ f()
+except:
+ from pudb import post_mortem
+ post_mortem()

0 comments on commit 97dfba7

Please sign in to comment.