Repository: spyder-ide/spyder

Issue:
Spyder freezes on new project creation
## Description

Spyder's GUI freezes on new project creation. When new project crated spyder need to be re-opened for working with recently created project because at project creation moment GUI freezes. Already exists projects opens fine. 

**What steps will reproduce the problem?**

1. Create new empty project
2. And spyder's GUI will freezes

If start spyder from terminal on freeze it shows exception in stdout/stderr

```
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/site-packages/spyder/plugins/projects.py", line 226, in create_new_project
    self.restart_consoles()
  File "/usr/local/lib/python3.5/site-packages/spyder/plugins/projects.py", line 385, in restart_consoles
    self.main.ipyconsole.restart()
  File "/usr/local/lib/python3.5/site-packages/spyder/plugins/ipythonconsole.py", line 1165, in restart
    client.shutdown()
  File "/usr/local/lib/python3.5/site-packages/spyder/widgets/ipythonconsole/client.py", line 300, in shutdown
    self.shellwidget.kernel_manager.shutdown_kernel()
  File "/usr/local/lib/python3.5/site-packages/jupyter_client/manager.py", line 302, in shutdown_kernel
    self.request_shutdown(restart=restart)
  File "/usr/local/lib/python3.5/site-packages/jupyter_client/manager.py", line 252, in request_shutdown
    self.session.send(self._control_socket, msg)
  File "/usr/local/lib/python3.5/site-packages/jupyter_client/session.py", line 684, in send
    stream.send_multipart(to_send, copy=copy)
AttributeError: 'NoneType' object has no attribute 'send_multipart'
```

## Versions and main components

* Spyder Version: 3.0.2
* Python Version: 3.5.2
* Operating system: macOS Sierra 10.12.1
* Qt: 5.7.0
* PyQt5: 5.7

## Dependencies

```
jedi >=0.8.1     :  0.9.0 (OK)
matplotlib >=1.0 :  1.5.3 (OK)
nbconvert >=4.0  :  4.2.0 (OK)
numpy >=1.7      :  1.11.2 (OK)
pandas >=0.13.1  :  0.19.1 (OK)
pep8 >=0.6       :  1.7.0 (OK)
psutil >=0.3     :  5.0.0 (OK)
pyflakes >=0.6.0 :  1.3.0 (OK)
pygments >=2.0   :  2.1.3 (OK)
pylint >=0.25    :  1.6.4 (OK)
qtconsole >=4.2.0:  4.2.1 (OK)
rope >=0.9.4     :  0.10.3 (OK)
sphinx >=0.6.6   :  1.5a1 (OK)
sympy >=0.7.3    :  1.0 (OK)
```


Discussion:
This problem seems to be related to `jupyter_client` instead of Spyder. A fix was provided here:

https://github.com/jupyter/jupyter_client/pull/226

However, it's very ugly that Spyder freezes because of this error.

----

@andfoy, please work on this one. It requires a simple fix: catch *any* error generated when running `client.shutdown()` in the `restart` method of `plugins/ipythonconsole.py` and show the error in a `QMessageBox.warning` dialog, saying something like

    It was not possible to restart the IPython console when switching to this project. The error was {}

and you put the error in `{}`

Resolving patch:
diff --git a/spyder/plugins/ipythonconsole.py b/spyder/plugins/ipythonconsole.py
--- a/spyder/plugins/ipythonconsole.py
+++ b/spyder/plugins/ipythonconsole.py
@@ -1177,7 +1177,13 @@ def restart(self):
         self.create_new_client_if_empty = False
         for i in range(len(self.clients)):
             client = self.clients[-1]
-            client.shutdown()
+            try:
+                client.shutdown()
+            except Exception as e:
+                QMessageBox.warning(self, _('Warning'),
+                    _("It was not possible to restart the IPython console "
+                      "when switching to this project. "
+                      "The error was {0}".format(e)), QMessageBox.Ok)
             self.close_client(client=client, force=True)
         self.create_new_client(give_focus=False)
         self.create_new_client_if_empty = True


Test patch: