【问题标题】:Enable and disable debugger in Ipython/Jupyter, skip breakpoints in disabled mode在 Ipython/Jupyter 中启用和禁用调试器,在禁用模式下跳过断点
【发布时间】:2018-03-28 08:24:36
【问题描述】:

我发现要在jupyter中激活调试器,我只需要使用set_trace

from IPython.core.debugger import set_trace

def add_to_life_universe_everything(x):
    answer = 42
    set_trace()
    answer += x

    return answer

add_to_life_universe_everything(12)

当我运行单元格时,我在add_to_life_universe_everything 方法中获得了一个交互式调试器断点。惊人的。但是,有时,事实上大多数时候我希望代码在没有断点的情况下运行。我可以通过删除/评论 set_trace() 来做到这一点,但我不想每次都这样做。

我正在寻找类似 debugger.disable() / debugger.enable() 的东西,它将禁用/启用所有断点,即 jupyter 中的 set_trace()

【问题讨论】:

  • 我也在寻找解决方案。全局禁用 IPython.core.debugger 的所有 Tracer()()

标签: python ipython jupyter-notebook


【解决方案1】:

您可以在 jupyter notebook 中使用 %debug 魔术命令,只有当您的代码中有错误时,它才会带您找到错误的位置。并且您可以使用所有调试命令来向上移动错误堆栈跟踪。

【讨论】:

    猜你喜欢
    • 2020-09-15
    • 1970-01-01
    • 2019-08-29
    • 2011-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多