6

如果我使用调试器,大多数时候我只想看看解释器在我的代码中做了什么。我想跳过我使用的框架和库的所有代码。

AFAIK 这被称为黑拳

如何使用 Python ipdb 或其他 Python 调试器执行此操作?

想象一下:

我使用我信任的 orm 框架,并且不想调试。

cut_hair_method(orm_object.user)

该方法cut_hair_method()是我的,我想调试它。

来自我使用的orm_object框架。调试器将进入 orm-code 并做一些我不关心的特殊事情。我没有办法告诉调试器:不要跳入orm代码!

更新

对于我的情况,很容易决定哪些代码应该在黑盒中,哪些代码不应该:代码$VIRTUAL_ENV/src/不在黑盒中,所有其他代码都在。除非我明确告诉调试器别的东西。

更新2

我有这篇文章中的“黑拳”这个名字:https ://hacks.mozilla.org/2013/08/new-features-of-firefox-developer-tools-episode-25/

4

2 回答 2

4

The Python debugger base class (bdb.Bdb) has an a .skip attribute, giving a list of module names to skip over. You can provide this list either when instantiation the debugger, or later. If you want to provide a negative list (list of module that are your own), or otherwise compute whether a module should be skipped, you can subclass the debugger class and override is_skipped_module.

于 2014-12-20T15:05:33.503 回答
0

由于 PyCharm 4.5 版有一个名为“Step into my code”的功能:https ://www.jetbrains.com/pycharm/whatsnew/#StepIntoCode

有用。我的情况是,我只想进入我的代码(Django 应用程序),而不是进入 django 本身的代码。默认快捷方式很复杂(alt-shift-F7),但很容易更改。

相关问题:https ://youtrack.jetbrains.com/issue/PY-14789

于 2015-05-19T08:05:17.640 回答