Repository: spyder-ide/spyder

Issue:
Error when restarting kernel
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

1. Try to restart the IPython Console kernel with the `Restart kernel` option from the context menu.

### Traceback
```python-traceback
Traceback (most recent call last):
  File "/home/daniel/.local/spyder-6/envs/spyder-runtime/lib/python3.11/site-packages/superqt/utils/_throttler.py", line 250, in _set_future_result
    result = self._func(*self._args[: self._max_args], **self._kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/daniel/.local/spyder-6/envs/spyder-runtime/lib/python3.11/site-packages/spyder/plugins/ipythonconsole/widgets/main_widget.py", line 2072, in restart_kernel
    km = client.kernel_handler.kernel_manager
         ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'bool' object has no attribute 'kernel_handler'
```

## Versions

* Spyder version: 6.0.0a6.dev197  (standalone)
* Python version: 3.11.9 64-bit
* Qt version: 5.15.8
* PyQt5 version: 5.15.9
* Operating System: Linux-5.15.0-105-generic-x86_64-with-glibc2.31

### Dependencies

```
# Mandatory:
aiohttp >=3.9.3                   :  3.9.5 (OK)
asyncssh >=2.0.0,<3.0.0           :  2.14.1 (OK)
atomicwrites >=1.2.0              :  1.4.1 (OK)
chardet >=2.0.0                   :  5.2.0 (OK)
cloudpickle >=0.5.0               :  3.0.0 (OK)
cookiecutter >=1.6.0              :  2.6.0 (OK)
diff_match_patch >=20181111       :  20230430 (OK)
intervaltree >=3.0.2              :  3.1.0 (OK)
IPython >=8.13.0,<9.0.0,!=8.17.1  :  8.24.0 (OK)
jedi >=0.17.2,<0.20.0             :  0.19.1 (OK)
jellyfish >=0.7                   :  1.0.3 (OK)
jsonschema >=3.2.0                :  4.22.0 (OK)
keyring >=17.0.0                  :  25.2.1 (OK)
nbconvert >=4.0                   :  7.16.4 (OK)
numpydoc >=0.6.0                  :  1.7.0 (OK)
parso >=0.7.0,<0.9.0              :  0.8.4 (OK)
pexpect >=4.4.0                   :  4.9.0 (OK)
pickleshare >=0.4                 :  0.7.5 (OK)
psutil >=5.3                      :  5.9.8 (OK)
pygments >=2.0                    :  2.18.0 (OK)
pylint >=3.1,<4                   :  3.2.0 (OK)
pylint_venv >=3.0.2               :  3.0.3 (OK)
pyls_spyder >=0.4.0               :  0.4.0 (OK)
pylsp >=1.11.0,<1.12.0            :  1.11.0 (OK)
pylsp_black >=2.0.0,<3.0.0        :  2.0.0 (OK)
pyuca >=1.2                       :  1.2 (OK)
qdarkstyle >=3.2.0,<3.3.0         :  3.2.3 (OK)
qstylizer >=0.2.2                 :  0.2.3 (OK)
qtawesome >=1.3.1,<1.4.0          :  1.3.1 (OK)
qtconsole >=5.5.1,<5.6.0          :  5.5.2 (OK)
qtpy >=2.4.0                      :  2.4.1 (OK)
rtree >=0.9.7                     :  1.2.0 (OK)
setuptools >=49.6.0               :  69.5.1 (OK)
sphinx >=0.6.6                    :  7.3.7 (OK)
spyder_kernels >=3.0.0b6,<3.0.0b7 :  3.0.0b6 (OK)
superqt >=0.6.1,<1.0.0            :  0.6.4 (OK)
textdistance >=4.2.0              :  4.6.2 (OK)
three_merge >=0.1.1               :  0.1.1 (OK)
watchdog >=0.10.3                 :  4.0.0 (OK)
xdg >=0.26                        :  0.28 (OK)
yarl >=1.9.4                      :  1.9.4 (OK)
zmq >=24.0.0                      :  26.0.3 (OK)

# Optional:
cython >=0.21                     :  3.0.10 (OK)
matplotlib >=3.0.0                :  3.8.4 (OK)
numpy >=1.7                       :  1.26.4 (OK)
pandas >=1.1.1                    :  2.2.2 (OK)
scipy >=0.17.0                    :  1.13.0 (OK)
sympy >=0.7.3                     :  1.12 (OK)
```

### Environment

<details><summary>Environment</summary>

```
# packages in environment at /home/daniel/miniconda3/envs/release:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       1_gnu    conda-forge
bleach                    4.1.0                    pypi_0    pypi
ca-certificates           2021.10.8            ha878542_0    conda-forge
certifi                   2021.10.8                pypi_0    pypi
cffi                      1.15.0                   pypi_0    pypi
charset-normalizer        2.0.7                    pypi_0    pypi
colorama                  0.4.4                    pypi_0    pypi
commonmark                0.9.1                    pypi_0    pypi
cryptography              35.0.0                   pypi_0    pypi
docutils                  0.18                     pypi_0    pypi
idna                      3.3                      pypi_0    pypi
importlib-metadata        4.8.2                    pypi_0    pypi
jeepney                   0.7.1                    pypi_0    pypi
jinja2                    3.0.3                    pypi_0    pypi
keyring                   23.2.1                   pypi_0    pypi
ld_impl_linux-64          2.36.1               hea4e1c9_2    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libgcc-ng                 11.2.0              h1d223b6_11    conda-forge
libgomp                   11.2.0              h1d223b6_11    conda-forge
libzlib                   1.2.11            h36c2ea0_1013    conda-forge
loghub                    0.5.1                    pypi_0    pypi
markupsafe                2.0.1                    pypi_0    pypi
ncurses                   6.2                  h58526e2_4    conda-forge
openssl                   3.0.0                h7f98852_2    conda-forge
packaging                 21.2                     pypi_0    pypi
pip                       24.0                     pypi_0    pypi
pkginfo                   1.8.2                    pypi_0    pypi
pycparser                 2.21                     pypi_0    pypi
pygments                  2.10.0                   pypi_0    pypi
pyparsing                 2.4.7                    pypi_0    pypi
python                    3.9.7           hf930737_3_cpython    conda-forge
python_abi                3.9                      2_cp39    conda-forge
readline                  8.1                  h46c0cb4_0    conda-forge
readme-renderer           35.0                     pypi_0    pypi
requests                  2.26.0                   pypi_0    pypi
requests-toolbelt         0.9.1                    pypi_0    pypi
rfc3986                   1.5.0                    pypi_0    pypi
rich                      12.5.1                   pypi_0    pypi
secretstorage             3.3.1                    pypi_0    pypi
setuptools                69.5.1                   pypi_0    pypi
six                       1.16.0                   pypi_0    pypi
sqlite                    3.36.0               h9cd32fc_2    conda-forge
tk                        8.6.11               h27826a3_1    conda-forge
tqdm                      4.62.3                   pypi_0    pypi
twine                     5.0.0                    pypi_0    pypi
tzdata                    2021e                he74cb21_0    conda-forge
urllib3                   1.26.7                   pypi_0    pypi
webencodings              0.5.1                    pypi_0    pypi
wheel                     0.43.0                   pypi_0    pypi
xz                        5.2.5                h516909a_1    conda-forge
zipp                      3.6.0                    pypi_0    pypi
zlib                      1.2.11            h36c2ea0_1013    conda-forge

```
</details>



Discussion:

Resolving patch:
diff --git a/spyder/plugins/ipythonconsole/widgets/main_widget.py b/spyder/plugins/ipythonconsole/widgets/main_widget.py
--- a/spyder/plugins/ipythonconsole/widgets/main_widget.py
+++ b/spyder/plugins/ipythonconsole/widgets/main_widget.py
@@ -394,7 +394,7 @@ def setup(self):
             IPythonConsoleWidgetActions.Restart,
             text=_("Restart kernel"),
             icon=self.create_icon('restart'),
-            triggered=self.restart_kernel,
+            triggered=lambda checked: self.restart_kernel(),
             register_shortcut=True
         )
         self.reset_action = self.create_action(


Test patch:
diff --git a/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py b/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py
--- a/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py
+++ b/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py
@@ -917,9 +917,12 @@ def test_restart_kernel(ipyconsole, mocker, qtbot):
     qtbot.waitUntil(
         lambda: 'HELLO' in shell._control.toPlainText(), timeout=SHELL_TIMEOUT)
 
-    # Restart kernel and wait until it's up again
+    # Restart kernel and wait until it's up again.
+    # NOTE: We trigger the restart_action instead of calling `restart_kernel`
+    # directly to also check that that action is working as expected and avoid
+    # regressions such as spyder-ide/spyder#22084.
     shell._prompt_html = None
-    ipyconsole.restart_kernel()
+    ipyconsole.get_widget().restart_action.trigger()
     qtbot.waitUntil(
         lambda: shell.spyder_kernel_ready and shell._prompt_html is not None,
         timeout=SHELL_TIMEOUT)