简体   繁体   中英

Python debugging - Spyder - Pause during execution

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.

( 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM