【问题标题】:Jupyter, Python, %Debug: Setting breakpoint in module doesn't workJupyter、Python、%Debug:在模块中设置断点不起作用
【发布时间】:2017-01-10 09:54:00
【问题描述】:

我正在使用 Jupyter Notebook。

考虑以下代码:

cell1

import pdbtest  

单元格2

%debug -b pdbtest.py:3
pdbtest.test(4,6)

单元格2结束

pdbtest.py 是一个与笔记本位于同一文件夹中的模块,包含:

def test(a,b):
    print("hello")
    a=a*2
    print("goodbye")
    b=b*2

通常the %debugmagic 应该在模块的第三行设置断点。运行时,此代码返回:

Breakpoint 1 at /home/depot/notebooks/pdbtest.py:3
NOTE: Enter 'c' at the ipdb>  prompt to continue execution.
hello
goodbye

看来控制台已经很好地理解了文件和断点应该在的位置,并给出了函数的返回值。 但是它不会在断点处停止!

有人有过同样的经历吗?

【问题讨论】:

  • 我通过 IPython repl 遇到了同样的问题。

标签: python debugging jupyter-notebook


【解决方案1】:

在您的示例中,%debug 魔术命令仅对同一行中紧随其后的 Python 代码有效,即没有任何内容。

如果你希望它对整个单元格有效,那么你应该使用%%debug:

%%debug -b pdbtest.py:3
pdbtest.test(4,6)

【讨论】:

    猜你喜欢
    • 2016-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-13
    • 2021-03-29
    • 2019-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多