Skip to content

Recursion Depth Exceeded Causes Crash #12197

Open

Description

@Veemon

In IDLE:

Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class Vec2:
...     def __init__(self, x=0.0, y=0.0):
...             self.x = x
...             self.y = y
...     def __mul__(self, other):
...             if type(other) is not Vec2:
...                     result = Vec2()
...                     result.x = self.x * other
...                     result.y = self.y * other
...                     return result
...             else:
...                     return self.x*other.x + self.y*other.y
...     def __rmul__(self, other):
...             # introduce bug where self and other should be swapped
...             return other * self
...
>>> x = Vec2(1.0, 1.0)
>>> x * 2
<__main__.Vec2 object at 0x0000016278FA7100>
>>> 2 * x
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 15, in __rmul__
  File "<stdin>", line 15, in __rmul__
  File "<stdin>", line 15, in __rmul__
  [Previous line repeated 996 more times]
RecursionError: maximum recursion depth exceeded

Running in iPython, instead of a RecursionError, the program directly crashes.
After the crash, the ERRORLEVEL flag is set to -1073741571.
On pip 19.2.3, these are the following dependencies,

Package          Version
---------------- -------
backcall         0.1.0
colorama         0.4.3
cycler           0.10.0
decorator        4.4.2
ipython          7.13.0
ipython-genutils 0.2.0
jedi             0.16.0
kiwisolver       1.1.0
matplotlib       3.2.1
numpy            1.18.2
parso            0.6.2
pickleshare      0.7.5
pip              19.2.3
prompt-toolkit   3.0.4
Pygments         2.6.1
pyparsing        2.4.6
python-dateutil  2.8.1
setuptools       41.2.0
six              1.14.0
traitlets        4.3.3
wcwidth          0.1.8

Activity

  1. Carreau commented on Mar 24, 2020

    @Carreau
    Member

    That is strange, it might be a windows specific error, I can't reproduce on the machines I have.

  2. jphme commented on Sep 9, 2020

    @jphme

    I can confirm this bug (RecursionError is not thrown and can't be catched but kernel restarts directly in ipython/jupyter)

    ipython 7.18.1 on current Windows 10

  3. acbart commented on Feb 26, 2021

    @acbart

    Confirmed on my machine:

    IPython 7.19.0 on current Windows 10.

    Frustrating, since I really need to be able to catch this error!

  4. acbart commented on Feb 26, 2021

    @acbart

    To make this more reproducible:

    import sys
    sys.setrecursionlimit(10000)
    
    exec('''def x():
         x()
    x()''')

    Changing the recursionlimit to be something like 1000 avoids the issue, though. I can recover from the maximum recursion error.

  5. crusaderky commented on Mar 2, 2021

    @crusaderky

    I can only reproduce this bug on Python 3.9 + pytest; pytest on python 3.8 is fine; pure python 3.9 is also fine for me.
    Windows 10 only; Ubuntu and MacOSX are fine.

    No need to start ipython; importing the module is enough.
    My reproducer:

    import IPython
    
    def f():
        f()
    
    try:
        f()
    except RecursionError:
        pass
    $ conda create -n demo python=3.9 ipython pytest
    
    $ conda activate demo
    
    $ conda list
    # Name                    Version                   Build  Channel
    atomicwrites              1.4.0                      py_0
    attrs                     20.3.0             pyhd3eb1b0_0
    backcall                  0.2.0              pyhd3eb1b0_0
    ca-certificates           2021.1.19            haa95532_0
    certifi                   2020.12.5        py39haa95532_0
    colorama                  0.4.4              pyhd3eb1b0_0
    decorator                 4.4.2              pyhd3eb1b0_0
    importlib-metadata        2.0.0                      py_1
    importlib_metadata        2.0.0                         1
    iniconfig                 1.1.1              pyhd3eb1b0_0
    ipython                   7.21.0           py39hd4e2768_0
    ipython_genutils          0.2.0              pyhd3eb1b0_1
    jedi                      0.17.2           py39haa95532_1
    more-itertools            8.7.0              pyhd3eb1b0_0
    openssl                   1.1.1j               h2bbff1b_0
    packaging                 20.9               pyhd3eb1b0_0
    parso                     0.7.0                      py_0
    pickleshare               0.7.5           pyhd3eb1b0_1003
    pip                       21.0.1           py39haa95532_0
    pluggy                    0.12.0                     py_0
    prompt-toolkit            3.0.8                      py_0
    py                        1.10.0             pyhd3eb1b0_0
    pygments                  2.8.0              pyhd3eb1b0_0
    pyparsing                 2.4.7              pyhd3eb1b0_0
    pytest                    6.2.2            py39haa95532_2
    python                    3.9.1                h6244533_2
    setuptools                52.0.0           py39haa95532_0
    six                       1.15.0           py39haa95532_0
    sqlite                    3.33.0               h2a8f88b_0
    toml                      0.10.1                     py_0
    traitlets                 5.0.5              pyhd3eb1b0_0
    tzdata                    2020f                h52ac0ba_0
    vc                        14.2                 h21ff451_1
    vs2015_runtime            14.27.29016          h5e58377_2
    wcwidth                   0.2.5                      py_0
    wheel                     0.36.2             pyhd3eb1b0_0
    wincertstore              0.2              py39h2bbff1b_0
    zipp                      3.4.0              pyhd3eb1b0_0
    zlib                      1.2.11               h62dcd97_4
    
    $ python test1.py
    (no error)
    
    $ pytest test1.py
      [...]
      File "test1.py", line 4 in f
      File "test1.py", line 4 in f
      ...
    (crash)
  6. crusaderky commented on Mar 18, 2021

    @crusaderky

    Now I can reproduce it on Python 3.8 and 3.9, without pytest

    # packages in environment at C:\Miniconda3\envs\demo:
    #
    # Name                    Version                   Build  Channel
    argon2-cffi               20.1.0           py38h2bbff1b_1  
    async_generator           1.10               pyhd3eb1b0_0  
    attrs                     20.3.0             pyhd3eb1b0_0  
    backcall                  0.2.0              pyhd3eb1b0_0  
    bleach                    3.3.0              pyhd3eb1b0_0  
    ca-certificates           2021.1.19            haa95532_1  
    certifi                   2020.12.5        py38haa95532_0  
    cffi                      1.14.5           py38hcd4344a_0  
    colorama                  0.4.4              pyhd3eb1b0_0  
    decorator                 4.4.2              pyhd3eb1b0_0  
    defusedxml                0.7.1              pyhd3eb1b0_0  
    entrypoints               0.3                      py38_0  
    importlib-metadata        3.7.3            py38haa95532_1  
    importlib_metadata        3.7.3                hd3eb1b0_1  
    ipykernel                 5.3.4            py38h5ca1d4c_0  
    ipython                   7.21.0           py38hd4e2768_0  
    ipython_genutils          0.2.0              pyhd3eb1b0_1  
    ipywidgets                7.6.3              pyhd3eb1b0_1  
    jedi                      0.17.2           py38haa95532_1  
    jinja2                    2.11.3             pyhd3eb1b0_0  
    jsonschema                3.2.0                      py_2  
    jupyter_client            6.1.7                      py_0  
    jupyter_core              4.7.1            py38haa95532_0  
    jupyterlab_pygments       0.1.2                      py_0  
    jupyterlab_widgets        1.0.0              pyhd3eb1b0_1  
    libsodium                 1.0.18               h62dcd97_0  
    m2w64-gcc-libgfortran     5.3.0                         6  
    m2w64-gcc-libs            5.3.0                         7  
    m2w64-gcc-libs-core       5.3.0                         7  
    m2w64-gmp                 6.1.0                         2  
    m2w64-libwinpthread-git   5.0.0.4634.697f757               2  
    markupsafe                1.1.1            py38he774522_0  
    mistune                   0.8.4           py38he774522_1000  
    msys2-conda-epoch         20160418                      1  
    nbclient                  0.5.3              pyhd3eb1b0_0  
    nbconvert                 6.0.7                    py38_0  
    nbformat                  5.1.2              pyhd3eb1b0_1  
    nest-asyncio              1.5.1              pyhd3eb1b0_0  
    notebook                  6.2.0            py38haa95532_0  
    openssl                   1.1.1j               h2bbff1b_0  
    packaging                 20.9               pyhd3eb1b0_0  
    pandoc                    2.12                 haa95532_0  
    pandocfilters             1.4.3            py38haa95532_1  
    parso                     0.7.0                      py_0  
    pickleshare               0.7.5           pyhd3eb1b0_1003  
    pip                       21.0.1           py38haa95532_0  
    prometheus_client         0.9.0              pyhd3eb1b0_0  
    prompt-toolkit            3.0.8                      py_0  
    pycparser                 2.20                       py_2  
    pygments                  2.8.1              pyhd3eb1b0_0  
    pyparsing                 2.4.7              pyhd3eb1b0_0  
    pyrsistent                0.17.3           py38he774522_0  
    python                    3.8.8                hdbf39b2_4  
    python-dateutil           2.8.1              pyhd3eb1b0_0  
    pywin32                   227              py38he774522_1  
    pywinpty                  0.5.7                    py38_0  
    pyzmq                     20.0.0           py38hd77b12b_1  
    send2trash                1.5.0              pyhd3eb1b0_1  
    setuptools                52.0.0           py38haa95532_0  
    six                       1.15.0           py38haa95532_0  
    sqlite                    3.35.1               h2bbff1b_0  
    terminado                 0.9.3            py38haa95532_0  
    testpath                  0.4.4              pyhd3eb1b0_0  
    tornado                   6.1              py38h2bbff1b_0  
    traitlets                 5.0.5              pyhd3eb1b0_0  
    vc                        14.2                 h21ff451_1  
    vs2015_runtime            14.27.29016          h5e58377_2  
    wcwidth                   0.2.5                      py_0  
    webencodings              0.5.1                    py38_1  
    wheel                     0.36.2             pyhd3eb1b0_0  
    widgetsnbextension        3.5.1                    py38_0  
    wincertstore              0.2                      py38_0  
    winpty                    0.4.3                         4  
    zeromq                    4.3.3                ha925a31_3  
    zipp                      3.4.1              pyhd3eb1b0_0  
    
  7. DiegoBaldassarMilleuno commented on Jun 24, 2022

    @DiegoBaldassarMilleuno

    I can confirm this is affecting me as well, with Python 3.10.4 on Windows 11; it is also affecting JupyterLab, as one might expect.

    Packages
    Package              Version
    -------------------- -----------
    anyio                3.6.1
    argon2-cffi          21.3.0
    argon2-cffi-bindings 21.2.0
    asttokens            2.0.5
    attrs                21.4.0
    Babel                2.10.1
    backcall             0.2.0
    beautifulsoup4       4.11.1
    bleach               5.0.0
    certifi              2021.10.8
    cffi                 1.15.0
    charset-normalizer   2.0.12
    colorama             0.4.4
    cycler               0.11.0
    debugpy              1.6.0
    decorator            5.1.1
    defusedxml           0.7.1
    entrypoints          0.4
    executing            0.8.3
    fastjsonschema       2.15.3
    fonttools            4.33.3
    idna                 3.3
    ipykernel            6.15.0
    ipympl               0.9.1
    ipython              8.4.0
    ipython-genutils     0.2.0
    ipywidgets           7.7.1
    jedi                 0.18.1
    Jinja2               3.1.2
    json5                0.9.8
    jsonschema           4.5.1
    jupyter-client       7.3.4
    jupyter-core         4.10.0
    jupyter-server       1.18.0
    jupyterlab           3.4.3
    jupyterlab-pygments  0.2.2
    jupyterlab-server    2.14.0
    jupyterlab-widgets   1.1.1
    kiwisolver           1.4.2
    MarkupSafe           2.1.1
    matplotlib           3.5.2
    matplotlib-inline    0.1.3
    mistune              0.8.4
    mpmath               1.2.1
    nbclassic            0.3.7
    nbclient             0.6.3
    nbconvert            6.5.0
    nbformat             5.4.0
    nest-asyncio         1.5.5
    notebook             6.4.12
    notebook-shim        0.1.0
    numpy                1.22.3
    packaging            21.3
    pandoc               2.2
    pandocfilters        1.5.0
    parso                0.8.3
    pickleshare          0.7.5
    Pillow               9.1.0
    pip                  22.1.2
    plumbum              1.7.2
    ply                  3.11
    prometheus-client    0.14.1
    prompt-toolkit       3.0.29
    psutil               5.9.0
    pure-eval            0.2.2
    pycparser            2.21
    Pygments             2.12.0
    pyparsing            3.0.9
    pyrsistent           0.18.1
    python-dateutil      2.8.2
    pytz                 2022.1
    pywin32              304
    pywinpty             2.0.5
    pyzmq                23.2.0
    requests             2.27.1
    scipy                1.8.0
    Send2Trash           1.8.0
    setuptools           58.1.0
    six                  1.16.0
    sniffio              1.2.0
    soupsieve            2.3.2.post1
    stack-data           0.2.0
    sympy                1.10.1
    terminado            0.15.0
    tinycss2             1.1.1
    tornado              6.1
    traitlets            5.2.1.post0
    urllib3              1.26.9
    wcwidth              0.2.5
    webencodings         0.5.1
    websocket-client     1.3.2
    widgetsnbextension   3.6.1
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions