notebook icon indicating copy to clipboard operation
notebook copied to clipboard

The code causes the kernel to die due to infinite recursion

Open CoolPlayLin opened this issue 2 years ago • 8 comments

Describe the bug A bug in the code caused the kernel to die

To Reproduce Steps to reproduce the behavior:

  • Using the following code can cause kernel death
class A:
    def __init__(self, data) -> None:
        self.data = data
    def __bool__(self) -> bool:
        return bool(a)
a = A("Test")
bool(a)

Expected behavior

  • Python reports errors due to infinite recursion image

Screenshots image

Desktop (please complete the following information):

  • OS: Windows 11 22H2
  • Browser: Edge
  • Version: 👇👇👇

image

CoolPlayLin avatar Jan 11 '23 05:01 CoolPlayLin

image

CoolPlayLin avatar Jan 11 '23 05:01 CoolPlayLin

Thanks for reporting @CoolPlayLin. A similar issue has previously been reported as well https://github.com/jupyter/notebook/issues/2648.

RRosio avatar Jan 12 '23 18:01 RRosio

You probably didn't get what I mean @RRosio I'm focusing on kernel bugs

CoolPlayLin avatar Jan 13 '23 05:01 CoolPlayLin

After running the above code, Python will prompt an error, but Jupyter notebook is the kernel directly dead @RRosio

CoolPlayLin avatar Jan 13 '23 05:01 CoolPlayLin

@RRosio

CoolPlayLin avatar Jan 21 '23 03:01 CoolPlayLin

@CoolPlayLin Thank you for clarifying this issue. This issue has been accepted but no one is actively working on it at the moment. If you'd like to look into this issue, we'd welcome a pull request!

RRosio avatar Jan 26 '23 18:01 RRosio

I had this same issue. My code that caused it to crash:

class Bug:
    def __post_init__(self): # NOTE: Should be __init__
        self._config = {"bug": True}
    def __getattr__(self, name):
        return self._config[name]

b = Bug()
b.bug

Running this code in the Python interpreter gives the following:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 5, in __getattr__
  File "<stdin>", line 5, in __getattr__
  File "<stdin>", line 5, in __getattr__
  [Previous line repeated 996 more times]
RecursionError: maximum recursion depth exceeded

Note that the following code, when run in a Jupyter Notebook, generates a recursion error as expected, without killing the kernel.

def inf_rec():
    inf_rec()
inf_rec()

blairfrandeen avatar Sep 12 '23 16:09 blairfrandeen

Any update?

CoolPlayLin avatar Nov 04 '23 15:11 CoolPlayLin