How to pause program execution in Pycharm (pause button not working)?

让人想犯罪 __ 提交于 2021-01-21 05:37:09

问题


While debugging my Python 3.5 pogram in Pycharm 5.0.4, I am trying to hit the pause button to find how why/where the program is hanging (as can be done in Visual Studio).

However, nothing happens: the pause button does not become grey and the resume button stays grey, and in the debugger tool window, "Frames are not available".

I tried with different basic programs, on Linux and on Windows, to no avail.

Is this a bug or am I missing something in how Pycharm debugging is supposed to work?

I also noticed that when a breakpoint is hit, only one thread is suspended and I could see no way to suspend other threads to inspect their stack frames. I would be interested to know how to achieve this thread-specific suspension as well.


回答1:


Sounds like your program is hanging on a sleep or something of that sort, or maybe on some native code.

If it was a regular python loop the pause python would work. I believe the problem is with python itself and not the debug tool you are using.

When you pause a python program you pause the interperter and so all threads that are running in the context of the interperter are paused and you can see the them in the frames window. Any thread that show the message "Frames not available in non-suspended state" is not suspended because it is was sleeping when you paused the program.

see this for how to debug c code Not working python breakpoints in C thread in pycharm or eclipse+pydev




回答2:


Within PyCharm, there is an option for debugging, that will allow you to step through your code, which may be of more use, rather than trying to pause the program.

You need to insert a break point in the code initially; just click in the grey bar at the line you want to break at:

Then you can press Alt+Shift+F9, or click Run > Debug in the menu to start stepping through the code from that point:

Once you have started the debug mode, click the button highlighted by the red circle - this will enable you to step through the code, looking at the variables, their assignments and if you receive any errors.

If you need to stop at any point, just hit the red Stop button on the left of the debug window.
The console tab will allow you to see what is being printed to the screen (if anything), and at what point, save you having loads of print statements like you would if debugging using Idle or similar IDEs

HTH



来源:https://stackoverflow.com/questions/35649704/how-to-pause-program-execution-in-pycharm-pause-button-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!