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

2

6

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.

Violetavioletta answered 26/2, 2016 at 10:49 Comment(0)
I
2

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

Infringement answered 11/8, 2016 at 6:39 Comment(0)
P
-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:

InsertBreakPoint

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

enter image description here

DebugStepThrough

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

Prospero answered 26/2, 2016 at 11:21 Comment(1)
Breakpoints are not very useful to suspend execution arbitrarily and determine which lines are hanging as in the case of a deadlock.Violetavioletta

© 2022 - 2024 — McMap. All rights reserved.