我正在尝试调试模块"main",它在"another_module"的第356行调用一个函数"broken_function".我在该函数中遇到错误,并希望在其开头添加断点.以下是列表.难道我做错了什么?原因,断点不起作用:
$ python -m pdb main
(Pdb) import sys
(Pdb) sys.path.append("/home/user/path/to/another/module")
(Pdb) import another_module
(Pdb) b another_module:356
Breakpoint 1 at /home/user/path/to/another/module/another_module.py:356
(Pdb) c
Traceback (most recent call last):
...
File "/home/user/path/to/another/module/another_module.py", line 383, in broken_function
f=open("../jobs/temptree.tre", "r")
IOError: [Errno 2] No such file or directory: '../jobs/temptree.tre'
Uncaught exception. Entering post mortem debugging
...
Run Code Online (Sandbox Code Playgroud)
Ria*_*zvi 21
您正确设置断点.我想它并没有停止,因为你打破的代码行没有被调用.把休息放在383号线上.
use*_*654 11
您还可以直接使用文件和行号设置断点,而无需导入sys或another_module.
(Pdb) b /home/user/path/to/another/module/another_module.py:383
Breakpoint 1 at /home/user/path/to/another/module/another_module.py:383
Run Code Online (Sandbox Code Playgroud)
请注意/home/user/path/to/another/module/another_module.py,正如其他人指出的那样,需要导入并且第 383 行需要可执行文件并在执行路径中使其中断。
如需更多帮助,请键入help b(或就此而言,help后跟任何其他命令)以获取有关该命令的更多信息。