ipykernel icon indicating copy to clipboard operation
ipykernel copied to clipboard

ipykernel restarts with "Restarting kernel..." message

Open eendebakpt opened this issue 3 years ago • 2 comments

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.

eendebakpt avatar Sep 21 '21 19:09 eendebakpt

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.

ccordoba12 avatar Sep 22 '21 17:09 ccordoba12

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.

thangleiter avatar Dec 29 '22 09:12 thangleiter