pdb调试器步进不适用于Jupyter Notebook

时间:2017-11-11 22:41:35

标签: python python-3.x debugging jupyter-notebook jupyter

我正在尝试在Jupyter笔记本中使用“pdb”python调试器(https://docs.python.org/3/library/pdb.html),但它没有按预期运行。

特别是,当我运行以下代码时

from pdb import set_trace

set_trace()
print("This is the next line")
for j in range(0,5):
    print(j)

按预期输入调试器,显示

--Return--
> <ipython-input-4-ed8fefd89436>(3)<module>()->None
-> set_trace()

使用(PBD)命令行。但是,当我在此命令行中输入n并点击“enter”,尝试将调试器移动到下一行时,会发生意外情况 - 输出更新为

--Return--
> <ipython-input-4-ed8fefd89436>(3)<module>()->None
-> set_trace()
(Pdb) n
> c:\python\lib\site-packages\ipython\core\interactiveshell.py(2913)run_code()
-> sys.excepthook = old_excepthook

再输入n几次

--Return--
> <ipython-input-4-ed8fefd89436>(3)<module>()->None
-> set_trace()
(Pdb) n
> c:\python\lib\site-packages\ipython\core\interactiveshell.py(2913)run_code()
-> sys.excepthook = old_excepthook
(Pdb) n
> c:\python\lib\site-packages\ipython\core\interactiveshell.py(2929)run_code()
-> outflag = False
(Pdb) n
> c:\python\lib\site-packages\ipython\core\interactiveshell.py(2930)run_code()
-> return outflag
(Pdb) n
--Return--
> c:\python\lib\site-packages\ipython\core\interactiveshell.py(2930)run_code()->False
-> return outflag
(Pdb) n
> c:\python\lib\site-packages\ipython\core\interactiveshell.py(2847)run_ast_nodes()
-> for i, node in enumerate(to_run_exec):

这里发生了什么?调试器正在逐步完成的代码不是我的......

1 个答案:

答案 0 :(得分:0)

改为使用此

from IPython.core.debugger import set_trace
set_trace()