0

The program in question is Pydial. I am running it in pycharm with this command.

python pydial.py chat config/Tut-hdc-CamInfo.cfg

I can run it only in my terminal. I am trying to debug the program, but only without running the program.

How do i debug the program while running it? I want to see the order of classes and methods being executed as the program runs, as opposed to the current situation where i can see the order of classes and methods being executed but the program doesnt run (i am not able to give any input to the program).

Sid
  • 71
  • 1
  • 3
  • 17
  • If you're running it in pycharm then just make a run configuration? – Sayse Aug 25 '17 at 08:10
  • but i dont have any configuration parameters – Sid Aug 25 '17 at 08:21
  • 1
    Read about [pdb](https://docs.python.org/2/library/pdb.html) and [python-debugging-tips](https://stackoverflow.com/questions/1623039/python-debugging-tips) – stovfl Aug 25 '17 at 19:18

1 Answers1

1

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
John Blischak
  • 1,102
  • 1
  • 14
  • 18