为什么在符号链接目录中使用代码时pdb不会在断点处停止?

问题描述 投票:0回答:1

我正在使用Python 3.7.3。我有两个文件:

tmp/add.py

def add(a,b):
    print("hello")
    return(a+b)

tmp/main.py

from add import add
a=9
b=10
c=add(a,b)

如果我跑步

$ python -m pdb tmp/main.py
> /home/user/tmp/main.py(1)<module>()
-> from add import add
(Pdb) b add.py : 2
Breakpoint 1 at /home/user/tmp/add.py:2
(Pdb) c
> /home/user/tmp/add.py(2)add()
-> print("hello")
(Pdb)

pdb正确地在断点处停止。现在,如果我创建到目录(ln -s tmp poo)的符号链接,并尝试在符号链接的目录上运行pdb

$ python -m pdb poo/main.py
<function save_history at 0x2aaab21e1f28>
> /home/user/poo/main.py(1)<module>()
-> from add import add
(Pdb) b add.py : 2
Breakpoint 1 at /home/user/tmp/add.py:2
(Pdb) c
hello
The program finished and will be restarted

很显然,pdb无法在断点处停止并且在符号链接方面遇到困难。

问题

是否有解决此问题的方法,还是只是停留在我的代码所在的目录并在其中运行pdb

python symlink pdb
1个回答
0
投票

似乎解决方案是键入文件的完整路径。

即。

from add import add
(Pdb) b /home/user/poo/add.py : 2
Breakpoint 1 at /home/user/poo/add.py:2
(Pdb) c
> /home/user/poo/add.py(2)add()
-> print("hello")
(Pdb)

由于需要更多的按键操作,所以还是有点臭。

© www.soinside.com 2019 - 2024. All rights reserved.