3

I wrote this piece of code and tried to debug it:

from time import *

for i in range (100):
    sleep(1)
    print(i)

I first run this script in debug mode, and try to pause it by clicking the pause button, but the pause button doesn't work at all, it just keep printing new numbers.

Then I directly run this script (not in the debug mode), the pause did stop pycharm from printing new numbers, but the script is actually still running in the background, when I resume the script, it prints a lot of numbers all of a sudden.

So how can I correctly pause the script execution?

I installed pycharm and python in a whole new windows 7, it still behaves like this.

The stop and rerun button works perfectly, breakpoints too. But the pause button never works.

DavidG
  • 24,279
  • 14
  • 89
  • 82
iouvxz
  • 89
  • 9
  • 27

2 Answers2

10

The pause ("Pause Output") button only temporarily suspends output to the terminal - it has no effect on the script execution. You may wish to use debug mode with breakpoints instead.

You can add breakpoints into your program by clicking in the space to the left of the text editor (the "Left Gutter", where line numbers appear, if you have them enabled).

See the Pycharm documentation for more information.

Tom Wyllie
  • 2,020
  • 13
  • 16
  • So ,nothing like that exists in pycharm ? If I want to pause the script execution and resume it later on ,the only choice is using breakpoints? – iouvxz Jun 28 '17 at 14:12
  • Nothing exists like this in pycharm __outside of debug mode__. But why should it? If you are trying to stop execution halfway through some code then you are not running it normally anyway, I'd argue that is always debugging. – Tom Wyllie Jun 28 '17 at 14:15
  • @Artyer I was developing C++ on visual studio in the last 3 years ,newbee to python and pycharm ,sorry . – iouvxz Jun 28 '17 at 14:16
  • Don't worry @iouvxz, I've been using JetBrains' IDEs for a few years and only noticed when you asked that question that the pause button actually only says "Pause Output". :) – Tom Wyllie Jun 28 '17 at 14:17
  • @TomWyllie I am debugging it ,but it just won't pause execution ,it either ignore my pause request or, at best ,it just stop showing its output to me but still keep running in the background .That makes me very confused . – iouvxz Jun 28 '17 at 14:20
1

Update 2022

We now have a pause button in debug mode :

enter image description here

enter image description here

Butanium
  • 726
  • 5
  • 19