question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Recursion Depth Exceeded Causes Crash

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
acbartcommented, Feb 26, 2021

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.

0reactions
DiegoBaldassarMilleunocommented, Jun 24, 2022

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
Read more comments on GitHub >

github_iconTop Results From Across the Web

Maximum recursion error depth causing crash? - Stack Overflow
I would check your logic, hitting the recursion depth could mean you a not correctly terminating your recursion logic. – AChampion. Aug 24,...
Read more >
Crash of my script maximum recursion depth exceeded : Forums
If you want something to run forever, restarting if it crashes for any reason, then the best place to set it up is...
Read more >
Why does Mathematica crash at a certain recursion depth?
$RecursionLimit: Recursion depth of 70000 exceeded during evaluation of 1+x. But at $RecursionLimit = 80000 , Mathematica crashes (i.e. goes ...
Read more >
Why does increasing the recursion limit to a number such as ...
The recursion limit is there specifically to avoid these types of crashes. Recursive functions have high memory requirements. Each recursion doubles the ...
Read more >
Crash with RecursionError: maximum recursion depth exceeded
Control: retitle -1 britney: Crash with RecursionError: maximum recursion depth exceeded. On Fri, 2022-05-06 at 12:41 +0200, Christian Marillat wrote:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found