Repository: spyder-ide/spyder

Issue:
Annoying "Are you sure you want to restart the kernel?"
## Problem Description

Dialog box "Are you sure you want to restart the kernel?" is quite annoying.

### What steps reproduce the problem?

1.  Right-click on iPython console tab
2.  Choose "Restart kernel"

### What is the expected output? What do you see instead?

I expect the kernel to restart.
Instead I get a dialog box that forces me to say "Yes".

(If somebody feels this dialog is really important, can it be made optional in Preferences?)

## Versions

* Spyder version:  3.3.0
* Python version: 3.6
* Operating System name/version:  Win10 x64

### Dependencies

IPython >=4.0     :  6.4.0 (OK)
cython >=0.21     :  0.28.3 (OK)
jedi >=0.9.0      :  0.12.1 (OK)
matplotlib >=2.0.0:  2.2.2 (OK)
nbconvert >=4.0   :  5.3.1 (OK)
numpy >=1.7       :  1.14.5 (OK)
pandas >=0.13.1   :  0.23.3 (OK)
pycodestyle >=2.3 :  2.4.0 (OK)
pyflakes >=0.6.0  :  2.0.0 (OK)
pygments >=2.0    :  2.2.0 (OK)
pylint >=0.25     :  1.9.2 (OK)
qtconsole >=4.2.0 :  4.3.1 (OK)
rope >=0.9.4      :  0.10.7 (OK)
sphinx >=0.6.6    :  1.7.5 (OK)
sympy >=0.7.3     :  1.1.1 (OK)




Discussion:
Thanks for the suggestion. We'll try to address it in a future release.

Resolving patch:
diff --git a/spyder/config/main.py b/spyder/config/main.py
--- a/spyder/config/main.py
+++ b/spyder/config/main.py
@@ -168,7 +168,8 @@
               'symbolic_math': False,
               'in_prompt': '',
               'out_prompt': '',
-              'show_elapsed_time': False
+              'show_elapsed_time': False,
+              'ask_before_restart': True
               }),
             ('variable_explorer',
              {
diff --git a/spyder/plugins/ipythonconsole.py b/spyder/plugins/ipythonconsole.py
--- a/spyder/plugins/ipythonconsole.py
+++ b/spyder/plugins/ipythonconsole.py
@@ -311,6 +311,11 @@ def setup_page(self):
                 tip=_("This option lets you hide the warning message shown\n"
                       "when resetting the namespace from Spyder."))
         show_time_box = newcb(_("Show elapsed time"), 'show_elapsed_time')
+        ask_restart_box = newcb(
+                _("Ask for confirmation before restarting"),
+                'ask_before_restart',
+                tip=_("This option lets you hide the warning message shown\n"
+                      "when restarting the kernel."))
 
         interface_layout = QVBoxLayout()
         interface_layout.addWidget(banner_box)
@@ -319,6 +324,7 @@ def setup_page(self):
         interface_layout.addWidget(ask_box)
         interface_layout.addWidget(reset_namespace_box)
         interface_layout.addWidget(show_time_box)
+        interface_layout.addWidget(ask_restart_box)
         interface_group.setLayout(interface_layout)
 
         comp_group = QGroupBox(_("Completion Type"))
@@ -741,6 +747,8 @@ def apply_plugin_settings(self, options):
         show_time_o = self.get_option(show_time_n)
         reset_namespace_n = 'show_reset_namespace_warning'
         reset_namespace_o = self.get_option(reset_namespace_n)
+        ask_before_restart_n = 'ask_before_restart'
+        ask_before_restart_o = self.get_option(ask_before_restart_n)
         for client in self.clients:
             control = client.get_control()
             if font_n in options:
@@ -754,6 +762,8 @@ def apply_plugin_settings(self, options):
                 client.set_elapsed_time_visible(show_time_o)
             if reset_namespace_n in options:
                 client.reset_warning = reset_namespace_o
+            if ask_before_restart_n in options:
+                client.ask_before_restart = ask_before_restart_o
 
     def toggle_view(self, checked):
         """Toggle view"""
@@ -1053,6 +1063,7 @@ def create_new_client(self, give_focus=True, filename='', is_cython=False):
         cf = self._new_connection_file()
         show_elapsed_time = self.get_option('show_elapsed_time')
         reset_warning = self.get_option('show_reset_namespace_warning')
+        ask_before_restart = self.get_option('ask_before_restart')
         client = ClientWidget(self, id_=client_id,
                               history_filename=get_conf_path('history.py'),
                               config_options=self.config_options(),
@@ -1061,7 +1072,8 @@ def create_new_client(self, give_focus=True, filename='', is_cython=False):
                               connection_file=cf,
                               menu_actions=self.menu_actions,
                               show_elapsed_time=show_elapsed_time,
-                              reset_warning=reset_warning)
+                              reset_warning=reset_warning,
+                              ask_before_restart=ask_before_restart)
         if self.testing:
             client.stderr_dir = self.test_dir
         self.add_tab(client, name=client.get_name(), filename=filename)
@@ -1761,6 +1773,7 @@ def _create_client_for_kernel(self, connection_file, hostname, sshkey,
         # Creating the client
         show_elapsed_time = self.get_option('show_elapsed_time')
         reset_warning = self.get_option('show_reset_namespace_warning')
+        ask_before_restart = self.get_option('ask_before_restart')
         client = ClientWidget(self,
                               id_=client_id,
                               given_name=given_name,
@@ -1774,7 +1787,8 @@ def _create_client_for_kernel(self, connection_file, hostname, sshkey,
                               external_kernel=external_kernel,
                               slave=True,
                               show_elapsed_time=show_elapsed_time,
-                              reset_warning=reset_warning)
+                              reset_warning=reset_warning,
+                              ask_before_restart=ask_before_restart)
 
         # Create kernel client
         kernel_client = QtKernelClient(connection_file=connection_file)
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
@@ -102,7 +102,8 @@ def __init__(self, plugin, id_,
                  menu_actions=None, slave=False,
                  external_kernel=False, given_name=None,
                  show_elapsed_time=False,
-                 reset_warning=True):
+                 reset_warning=True,
+                 ask_before_restart=True):
         super(ClientWidget, self).__init__(plugin)
         SaveHistoryMixin.__init__(self, history_filename)
 
@@ -116,6 +117,7 @@ def __init__(self, plugin, id_,
         self.given_name = given_name
         self.show_elapsed_time = show_elapsed_time
         self.reset_warning = reset_warning
+        self.ask_before_restart = ask_before_restart
 
         # --- Other attrs
         self.options_button = None
@@ -473,7 +475,7 @@ def restart_kernel(self):
         """
         sw = self.shellwidget
 
-        if not running_under_pytest():
+        if not running_under_pytest() and self.ask_before_restart:
             message = _('Are you sure you want to restart the kernel?')
             buttons = QMessageBox.Yes | QMessageBox.No
             result = QMessageBox.question(self, _('Restart kernel?'),
@@ -481,7 +483,9 @@ def restart_kernel(self):
         else:
             result = None
 
-        if result == QMessageBox.Yes or running_under_pytest():
+        if (result == QMessageBox.Yes or
+           running_under_pytest() or
+           not self.ask_before_restart):
             if sw.kernel_manager:
                 if self.infowidget.isVisible():
                     self.infowidget.hide()


Test patch: