Skip to content

Commit

Permalink
Add pudb.b
Browse files Browse the repository at this point in the history
This lets you just run

import pudb.b

to trigger a set_trace(). It works by monkey-patching
__builtins__.__import__. It does not yet work in Python 3.3, due to the new
import mechanism.

See #109.
  • Loading branch information
asmeurer committed Feb 27, 2014
1 parent 254630e commit f6492a5
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pudb/b.py
@@ -0,0 +1,19 @@
import sys

from pudb import _get_debugger, set_interrupt_handler

def __myimport__(name, *args, **kwargs):
if name == 'pudb.b':
set_trace()
return __origimport__(name, *args, **kwargs)

# Will only be run on first import
__builtins__['__origimport__'] = __import__
__builtins__['__import__'] = __myimport__

def set_trace():
dbg = _get_debugger()
set_interrupt_handler()
dbg.set_trace(sys._getframe().f_back.f_back)

set_trace()

0 comments on commit f6492a5

Please sign in to comment.