Repository: spyder-ide/spyder

Issue:
RuntimeError when interrupting kernel
## Description

**What steps will reproduce the problem?**

1. 
2. 
3. 

**What is the expected output? What do you see instead?**


**Please provide any additional information below**

  File "/Users/LZQ/anaconda3/lib/python3.6/site-packages/spyder/plugins/projects.py", line 181, in <lambda>
    triggered=lambda v, path=project: self.open_project(path=path))
  File "/Users/LZQ/anaconda3/lib/python3.6/site-packages/spyder/plugins/projects.py", line 270, in open_project
    self.restart_consoles()
  File "/Users/LZQ/anaconda3/lib/python3.6/site-packages/spyder/plugins/projects.py", line 388, in restart_consoles
    self.main.ipyconsole.restart()
  File "/Users/LZQ/anaconda3/lib/python3.6/site-packages/spyder/plugins/ipythonconsole.py", line 1335, in restart
    self.close_client(client=client, force=True)
  File "/Users/LZQ/anaconda3/lib/python3.6/site-packages/spyder/plugins/ipythonconsole.py", line 1253, in close_client
    client.stop_button_click_handler()
  File "/Users/LZQ/anaconda3/lib/python3.6/site-packages/spyder/widgets/ipythonconsole/client.py", line 237, in stop_button_click_handler
    self.interrupt_kernel()
  File "/Users/LZQ/anaconda3/lib/python3.6/site-packages/spyder/widgets/ipythonconsole/client.py", line 393, in interrupt_kernel
    self.shellwidget.request_interrupt_kernel()
  File "/Users/LZQ/anaconda3/lib/python3.6/site-packages/qtconsole/frontend_widget.py", line 345, in request_interrupt_kernel
    self.interrupt_kernel()
  File "/Users/LZQ/anaconda3/lib/python3.6/site-packages/qtconsole/frontend_widget.py", line 638, in interrupt_kernel
    self.kernel_manager.interrupt_kernel()
  File "/Users/LZQ/anaconda3/lib/python3.6/site-packages/jupyter_client/manager.py", line 408, in interrupt_kernel
    raise RuntimeError("Cannot interrupt kernel. No kernel is running!")
RuntimeError: Cannot interrupt kernel. No kernel is running!


## Version and main components

* Spyder Version: 3.2.4 
* Python Version: 3.6.3
* Qt Versions: 5.6.2, PyQt5 5.6 on Darwin

## Dependencies
```
pyflakes >=0.6.0 :  1.6.0 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pygments >=2.0   :  2.2.0 (OK)
pandas >=0.13.1  :  0.20.3 (OK)
numpy >=1.7      :  1.13.3 (OK)
sphinx >=0.6.6   :  1.6.3 (OK)
rope >=0.9.4     :  0.10.5 (OK)
jedi >=0.9.0     :  0.10.2 (OK)
psutil >=0.3     :  5.4.0 (OK)
nbconvert >=4.0  :  5.3.1 (OK)
sympy >=0.7.3    :  1.1.1 (OK)
cython >=0.21    :  0.26.1 (OK)
qtconsole >=4.2.0:  4.3.1 (OK)
IPython >=4.0    :  6.1.0 (OK)
pylint >=0.25    :  1.7.4 (OK)

```



Discussion:
@dalthviz, please catch the `RuntimeError` around `self.shellwidget.request_interrupt_kernel()` and pass.

Resolving patch:
diff --git a/spyder/widgets/ipythonconsole/client.py b/spyder/widgets/ipythonconsole/client.py
--- a/spyder/widgets/ipythonconsole/client.py
+++ b/spyder/widgets/ipythonconsole/client.py
@@ -445,7 +445,12 @@ def shutdown(self):
 
     def interrupt_kernel(self):
         """Interrupt the associanted Spyder kernel if it's running"""
-        self.shellwidget.request_interrupt_kernel()
+        # Needed to prevent a crash when a kernel is not running.
+        # See issue 6299
+        try:
+            self.shellwidget.request_interrupt_kernel()
+        except RuntimeError:
+            pass
 
     @Slot()
     def restart_kernel(self):


Test patch: