2

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.

CarlosH
  • 319
  • 1
  • 4
  • 8

2 Answers2

1

(Spyder maintainer here) This functionality is already available in our master branch, which means it'll be part of Spyder 6, to be released in 2023. We added a new Debugger pane which has a button to interrupt the current computation in order to enter the debugger and check why it's taking so long.

To resume execution afterwards, you'd need to write in the IPdb prompt the command !continue.

Carlos Cordoba
  • 33,273
  • 10
  • 95
  • 124
0

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.

innicoder
  • 2,612
  • 3
  • 14
  • 29