pdb 跳过了一个隐藏帧问题

PyW*_*797 5 python ipython pdb

每当我尝试在 ipython 单元中运行该程序时,都会出现一个奇怪的错误。

test_pts = sorted_points
new_segments = []
import pdb; pdb.set_trace()
for i in range(0, len(test_pts)-1):
    x1 = test_pts[i][0]; y1 = test_pts[i][1]; x2 = test_pts[i][2]; y2 = test_pts[i][3]; angle1 = test_pts[i][4]
    print(x1, y1, x2, y2, angle1)
    for j in range(i + 1, len(test_pts)):
        n_x1 = test_pts[j][0]; n_y1 = test_pts[j][1]; n_x2 = test_pts[j][2]; n_y2 = test_pts[j][3]; angle2 = test_pts[j][4]
        if (isclose(angle1, angle2, rel_tol = 1)) and (isclose(x1, x2, rel_tol = 1) and (isclose(y1, y1, rel_tol = 1))):
            
            print(n_x1, n_y1, n_x2, n_y2, angle2) 
            break  
Run Code Online (Sandbox Code Playgroud)

下面的堆栈跟踪 -> 我觉得这个问题不可重现,而且它甚至不是特定于代码的,即我编写的​​代码没有任何问题,但我无法弄清楚是什么导致了这种行为。

# %% LINE EXTENSION - CONNECT...
--Return--
None
> (3)()
      1 test_pts = sorted_points
      2 new_segments = []
----> 3 import pdb; pdb.set_trace()
      4 for i in range(0, len(test_pts)-1):
      5     x1 = test_pts[i][0]; y1 = test_pts[i][1]; x2 = test_pts[i][2]; y2 = test_pts[i][3]; angle1 = test_pts[i][4]

    [... skipped 1 hidden frame]

> /home/and/CERLAB/lib/python3.8/site-packages/IPython/core/interactiveshell.py(3346)run_code()
   3344             finally:
   3345                 # Reset our crash handler in place
-> 3346                 sys.excepthook = old_excepthook
   3347         except SystemExit as e:
   3348             if result is not None:
Run Code Online (Sandbox Code Playgroud)

PyW*_*797 1

我仍然不确定问题到底是什么 - 这不是在普通 python 文件中发生的事情,似乎只发生在 .ipnyb 文件中。

以这种方式设置的断点只有在函数内部时才起作用,否则不起作用。因此,基本上,如果您遇到此问题,请确保该语句位于函数内部。