user1805743
user1805743

Reputation: 1215

How does a good python debugging workflow look like?

My latest python debugging workflow appears extremely slow to me, and little satifying. How can I improve?

Setting: I work with some third-party python packages from github.

Workflow:

  1. run into error after entering some command to the terminal (Ubuntu WSL, python 3.7)
  2. read terminal error message output, most likely the first or last one is helpful
  3. from the last message i take the code reference (ctrl+left mouse in vscode) and look at the code
  4. i find some function call in the third party module that looks very unrelated to the problem
  5. i add import pdb to the module, and a pdb.set_trace() before that function call
  6. i run the program again, and it stops at the breakpoint
  7. using n,r,u,d i try to navigate closer to the source of the error
  8. i eventually find some error raise condition in some other module, where some property of a certain variable is checked. the variable itself is defined some levels up in the stack
  9. re-running the program and stopping at the same breakpoint as before, i try to navigate to the point where the variable is set. I don't know on which level of the stack it is set, so i miss it sometimes. I set intermediate breakpoints to save me some work when re-running
  10. i finally find the actual cause of the error. I can check out the workspace and eventually fix the error.
  11. i go through all the modules and remove the import pdb and the pdb.set_trace

Thanks for any suggestions

Upvotes: 0

Views: 197

Answers (2)

ahed87
ahed87

Reputation: 1360

are you using an IDE, not fully clear in your question?

they tend to have graphic ways of setting breakpoints and stepping, and it saves the hassle of changing the source.

not going into ide opinions, but examples of ide's with debuggers are spyder, thonny and others.

you can also run the debugger via commandline to avoid changing source, but I don't think that's the way to go if you are looking to simplify the cognotive load.

Upvotes: 1

j suman
j suman

Reputation: 125

Yes these things you have to do and in extra you can do include logging everywhere as applicable to get exact point where it got occurred.

Upvotes: 0

Related Questions