Home > OS >  Python debugging - Spyder - Pause during execution
Python debugging - Spyder - Pause during execution

Time:06-09

My python code is taking longer than expected to run. I am using spyder 5.2 and python 3.9. Is there a way to pause execution arbitrarily to check the line that is currently running and examine the variable explorer? I would like the variable explorer to show local variables within a function if a function is running at the time.

After checking the code, I would like to restart the code from the point it had stopped.

Notice that I am not referring to setting breakpoints before the code is run. Rather, what I want is to be able to pause the code at will, during execution.

CodePudding user response:

Yeah, you can do this in PyCharm. However, it would be wise to check out the documentation on the pdb. https://docs.python.org/3/library/pdb.html

Usually as in other languages we use print() to debug. However, this doesn't work in every situation.

CodePudding user response:

(Spyder maintainer here) The only way I know of to pause execution anywhere in your code is to write the command breakpoint() in the line before the one that's giving you troubles.

To resume execution afterwards, please write in the IPdb prompt the command !continue.

Note: You can add as many breakpoint() commands in your code as you want. Your code will jump from one to the other after resuming execution.

  • Related