From f6492a53980313a0930ec87bf8b99cc0e963e767 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Thu, 27 Feb 2014 10:23:12 -0600 Subject: [PATCH] Add pudb.b 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. --- pudb/b.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 pudb/b.py diff --git a/pudb/b.py b/pudb/b.py new file mode 100644 index 0000000..5e3138d --- /dev/null +++ b/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()