To start debugging at the beginning of the script, add -m pdb
. Once you've entered the debugger, type n
to execute the next line, s
to step into a function, or exit
to stop debugging. Type ?
to see all of the pdb options.
python -m pdb pydial.py chat config/Tut-hdc-CamInfo.cfg
> /home/jdb-work/repos/pydial/pydial.py(25)<module>()
-> import os
(Pdb) list
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
22 #
23 ###############################################################################
24
25 -> import os
26 from scriptine import run, path, log, command
27 import re
28 import numpy as np
29
30 # Uncomment for mac os users
(Pdb) ?
Documented commands (type help <topic>):
========================================
EOF bt cont enable jump pp run unt
a c continue exit l q s until
alias cl d h list quit step up
args clear debug help n r tbreak w
b commands disable ignore next restart u whatis
break condition down j p return unalias where
Miscellaneous help topics:
==========================
exec pdb
Undocumented commands:
======================
retval rv
(Pdb) exit
If you know the lines of code you wish to debug, you can insert import pdb; pdb.set_trace()
directly into the script and then run the command as normal. This will stop execution at that exact point.
python pydial.py chat config/Tut-hdc-CamInfo.cfg
An alternative debugger you can install is the IPython debugger, ipdb. To use it you can add -m ipdb
or insert import ipdb; ipdb.set_trace()
and again run the command as normal.
Below is code to reproduce my example:
git clone git@bitbucket.org:dialoguesystems/pydial.git
cd pydial
# Switch the commit I used when creating this example
git checkout c215003f25b959ee350e192079d88e138e6e8dbf
# Create a conda environment
conda create -n pydial python=2.7 ipython ipdb
source activate pydial
pip install -r requirements.txt
# All the requirements weren't in requirements.txt
pip install scriptine matplotlib
python -m pdb pydial.py chat config/Tut-hdc-CamInfo.cfg