python debugger initialising with file

别来无恙 提交于 2019-12-11 07:33:59

问题


I am running a code with pdb

python -m pdb somecode.py 3

I would like to pass a file on the command line, where I can specify the breakpoints. The code selects some dataset thought the passed parameter -- in this case 3. I am running this script on a cluster. I know it is possible setting up .pdbrc, but I have some jobs running this code on different datasets (on those datasets the code works properly) and I don't want to interfere with that -- actually the other jobs are on the cluster queue and they could start anytime.

EDIT: would it be possible to set breakpoints, continue to next breakpoint, set a variable, continue to next breakpoint?


回答1:


You can use -c option (python 3 only). Docs quote (https://docs.python.org/3/library/pdb.html):

New in version 3.2: pdb.py now accepts a -c option that executes commands as if given in a .pdbrc file, see Debugger Commands.

to set a breakpoint on line 3 (and go to it - second '-c' need for this):

python -m pdb -c "b 3" -c c somecode.py 3

about sequence of instructions: yes, multiple -c options = multiple instructions. But it seems that with this method you cant set variables: -c "aaa=1" not works. You can try to use alias command to predefine some vars through command line args - additional manual command in pdb and all needed will be set:

python -m pdb -c "b 3" -c c -c "alias setvars aaa=1;bbb=1" somecode.py 3
(Pdb) setvars
(Pdb) aaa
1
(Pdb) bbb
1
(Pdb)


来源:https://stackoverflow.com/questions/50065682/python-debugger-initialising-with-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!