ipython / ipykernel

IPython Kernel for Jupyter
https://ipykernel.readthedocs.io/en/stable/
BSD 3-Clause "New" or "Revised" License
649 stars 367 forks source link

ipykernel restarts with "Restarting kernel..." message #776

Open eendebakpt opened 3 years ago

eendebakpt commented 3 years ago

The following minimal example results in the qtconsole restarting

import numpy as np
remaining_parameters=[]

cost_function_first = lambda x: cost_function_first(np.append(x, remaining_parameters))

cost_function_first([0.])

with error message

Kernel died, restarting

The same happens within a Spyder console

The minimal example has a clear problem: an infinite recursion. But in a normal python session this results in a normal exception with clear error message, e.g.

...
  File "C:\develop\env-py39\lib\site-packages\numpy\core\fromnumeric.py", line 1819, in ravel
    if isinstance(a, np.matrix):
RecursionError: maximum recursion depth exceeded while calling a Python object

Within qtconsole at least a clear error message should be generated. And preferably the console not restarted. Within jupyter notebook executing the minimal example also results in a crash without proper error messages.

ccordoba12 commented 3 years ago

I want to point out that this doesn't happen on Linux, i.e. I can see the RecursionError raised in both Qtconsole and Spyder.

thangleiter commented 1 year ago

I can confirm this is still happening (IPython 8.7.0) on Python 3.9 and 3.10, but not on Python 3.11. The Spyder kernel is a little bit more forthcoming in the error message:

Python 3.10.8 | packaged by conda-forge | (main, Nov 24 2022, 14:07:00) [MSC v.1916 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

IPython  -- An enhanced Interactive Python.

In [1]: def foo():
   ...:     foo()
In [2]: foo()

Windows fatal exception: stack overflow

Main thread:
Current thread 0x0000454c (most recent call first):
  File "C:\Users\hangleiter\AppData\Local\Temp\ipykernel_6432\1578689351.py", line 2 in foo
  File "C:\Users\hangleiter\AppData\Local\Temp\ipykernel_6432\1578689351.py", line 2 in foo
  ...

Restarting kernel...

As @ccordoba12 stated, on Linux this is not an issue.