Repository: spyder-ide/spyder

Issue:
"Stop the current command" stops only the first run after "Run file" button is pressed more than one time
## Problem Description

(I thought this issue has already been reported, but I couldn't find anything like this.)

When a script is executed by pressing the "Run file" button more than one time, pressing the "Stop the current command" button in the console indeed stops the first run, but the other runs continue. Moreover, the "Stop the current command" is grayed out after the first script is stopped, hence there is no way to stop the second script.

### What steps will reproduce the problem?

1. Write dummy script that takes some time to run, for example:
```
from time import sleep

for i in range(5):
    print(i)
    sleep(1)
    
print('done')
```
2. Set up the run configuration (Run -> Configurations per file): select "Execute in current console"
3. Run the file by pressing the green "Run file" button. Let it print one or two numbers, and then press the "Run file" button again.
4. Before the first run finishes (before it prints "5"), press the red "Stop the current command" button in the console window.
5. Both scripts will be interrupted - as expected
6. Now let's change the run configuration to "execute in a dedicated console"
7. Run the file by pressing the green "Run file" button. Let it print one or two numbers, and then press the "Run file" button again.
8. Before the first run finishes (before it prints "5"), press the red "Stop the current command" button in the console window. The first script will be interrupted, but the second one will still start its execution and it will start printing numbers, like this:
```
runfile('C:/Users/username/.spyder-py3/temp.py', wdir='C:/Users/username/.spyder-py3')
0
1

2
Traceback (most recent call last):

  File "<ipython-input-9-18c95d7ea4c8>", line 1, in <module>
    runfile('C:/Users/username/.spyder-py3/temp.py', wdir='C:/Users/username/.spyder-py3')

  File "C:\Users\username\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
    execfile(filename, namespace)

  File "C:\Users\username\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/username/.spyder-py3/temp.py", line 12, in <module>
    sleep(1)

KeyboardInterrupt


runfile('C:/Users/username/.spyder-py3/temp.py', wdir='C:/Users/username/.spyder-py3')
ERROR: execution aborted
0
1
2
3
4
done
```
9. What is even worse, is that the red "Stop the current command" button becomes inactive after you press it for first time in order to stop the first run.

## Package Versions

* Spyder version: 3.2.8 
* Python version: 3.6.5 64 bits
* Qt version: 5.9.4
* PyQt5 version: 5.9.2
* Operating system: Windows 10

### Dependencies

```
IPython >=4.0    :  6.4.0 (OK)
cython >=0.21    :  0.28.2 (OK)
jedi >=0.9.0     :  0.12.0 (OK)
nbconvert >=4.0  :  5.3.1 (OK)
numpy >=1.7      :  1.14.3 (OK)
pandas >=0.13.1  :  0.23.0 (OK)
pycodestyle >=2.3:  2.4.0 (OK)
pyflakes >=0.6.0 :  1.6.0 (OK)
pygments >=2.0   :  2.2.0 (OK)
pylint >=0.25    :  1.8.4 (OK)
qtconsole >=4.2.0:  4.3.1 (OK)
rope >=0.9.4     :  0.10.7 (OK)
sphinx >=0.6.6   :  1.7.4 (OK)
sympy >=0.7.3    :  1.1.1 (OK)
```

Originally, discovered by @jenshnielsen in mid 2017.


Discussion:
@astafan8, thanks a lot for the detailed description. I was able to reproduce it on my side and I know how to fix it. A fix for it will be available in our next version (3.3.0).

> What is even worse, is that the red "Stop the current command" button becomes inactive after you press it for first time in order to stop the first run.

This was already fixed and it'll be part of 3.3.0. See PR #7245.

Resolving patch:
diff --git a/spyder/plugins/ipythonconsole.py b/spyder/plugins/ipythonconsole.py
--- a/spyder/plugins/ipythonconsole.py
+++ b/spyder/plugins/ipythonconsole.py
@@ -956,7 +956,12 @@ def run_script(self, filename, wdir, args, debug, post_mortem,
                     line += " %s" % norm(args)
 
             try:
-                if client.shellwidget._reading:
+                if client.shellwidget._executing:
+                    # Don't allow multiple executions when there's
+                    # still an execution taking place
+                    # Fixes issue 7293
+                    pass
+                elif client.shellwidget._reading:
                     client.shellwidget._append_html(
                         _("<br><b>Please exit from debugging before trying to "
                           "run a file in this console.</b>\n<hr><br>"),


Test patch: