Skip to content

Commit

Permalink
Merge pull request #17052 from ccordoba12/reconfigure-client-on-kerne…
Browse files Browse the repository at this point in the history
…l-restart

PR: Reconfigure client before a kernel restart (IPython console)
  • Loading branch information
ccordoba12 authored Dec 19, 2021
2 parents 157c372 + 929ee81 commit e67286d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
10 changes: 9 additions & 1 deletion spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from spyder.plugins.help.utils.sphinxify import CSS_PATH
from spyder.plugins.ipythonconsole.plugin import IPythonConsole
from spyder.plugins.ipythonconsole.utils.style import create_style_class
from spyder.plugins.ipythonconsole.widgets import ClientWidget
from spyder.utils.programs import get_temp_dir
from spyder.utils.conda import is_conda_env

Expand Down Expand Up @@ -1126,10 +1127,13 @@ def test_clear_and_reset_magics_dbg(ipyconsole, qtbot):


@flaky(max_runs=3)
def test_restart_kernel(ipyconsole, qtbot):
def test_restart_kernel(ipyconsole, mocker, qtbot):
"""
Test that kernel is restarted correctly
"""
# Mock method we want to check
mocker.patch.object(ClientWidget, "_show_mpl_backend_errors")

shell = ipyconsole.get_current_shellwidget()
qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT)

Expand All @@ -1145,6 +1149,10 @@ def test_restart_kernel(ipyconsole, qtbot):
assert 'Restarting kernel...' in shell._control.toPlainText()
assert not shell.is_defined('a')

# Check that we try to show Matplotlib backend errors at the beginning and
# after the restart.
assert ClientWidget._show_mpl_backend_errors.call_count == 2


@flaky(max_runs=3)
def test_load_kernel_file_from_id(ipyconsole, qtbot):
Expand Down
10 changes: 7 additions & 3 deletions spyder/plugins/ipythonconsole/widgets/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,10 @@ def __del__(self):
self.restart_thread.wait()

# ----- Private methods ---------------------------------------------------
def _before_prompt_is_ready(self):
"""Configure shellwidget before kernel is connected."""
self._show_loading_page()
def _before_prompt_is_ready(self, show_loading_page=True):
"""Configuration before kernel is connected."""
if show_loading_page:
self._show_loading_page()
self.shellwidget.sig_prompt_ready.connect(
self._when_prompt_is_ready)
# If remote execution, the loading page should be hidden as well
Expand Down Expand Up @@ -636,6 +637,9 @@ def restart_kernel(self):
sw.kernel_manager.stop_restarter()
sw.kernel_manager.autorestart = False

# Reconfigure client before the new kernel is connected again.
self._before_prompt_is_ready(show_loading_page=False)

# Create and run restarting thread
if (self.restart_thread is not None
and self.restart_thread.isRunning()):
Expand Down
1 change: 0 additions & 1 deletion spyder/plugins/ipythonconsole/widgets/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
_, is_pynsist, running_in_mac_app, running_under_pytest)
from spyder.py3compat import to_text_string
from spyder.utils.palette import SpyderPalette
from spyder.utils import encoding
from spyder.utils.clipboard_helper import CLIPBOARD_HELPER
from spyder.utils import syntaxhighlighters as sh
from spyder.plugins.ipythonconsole.utils.style import (
Expand Down

0 comments on commit e67286d

Please sign in to comment.