This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Exception catching function crashes on recursive list
Type: crash Stage: resolved
Components: Interpreter Core Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: corona10, stestagg, steven.daprano
Priority: normal Keywords:

Created on 2021-01-01 05:16 by steven.daprano, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg384150 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-01-01 05:16
This function crashes on the following recursive list:


def length(x):
    try:
        return sum(length(i) for i in x)
    except Exception:
        return 1


a = [[1, 2, 3], [4, 5, 6]]
a.append(a)
length(a)


Crashes:


Fatal Python error: _Py_CheckRecursiveCall: Cannot recover from stack overflow.
Python runtime state: initialized

Current thread 0x00007eff18d77740 (most recent call first):
  File "<stdin>", line 3 in length
  File "<stdin>", line 3 in <genexpr>
  File "<stdin>", line 3 in length
  File "<stdin>", line 3 in <genexpr>
  ...
Aborted (core dumped)




For brevity I've cut some of the output. There are about fifty pairs of "line 3 in length"/line 3 in <genexpr>" lines, all identical.
msg384162 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2021-01-01 11:37
FYI,I am able to reproduce on Python 3.9
The master version is not able to reproduce.
msg384174 - (view) Author: Steve Stagg (stestagg) Date: 2021-01-01 14:30
This is fixed by https://github.com/python/cpython/pull/23744
History
Date User Action Args
2022-04-11 14:59:39adminsetgithub: 86967
2021-06-09 23:56:47corona10setstatus: open -> closed
stage: resolved
resolution: fixed
versions: + Python 3.8, Python 3.10, - Python 3.7
2021-01-01 14:30:26stestaggsetnosy: + stestagg
messages: + msg384174
2021-01-01 11:37:21corona10setnosy: + corona10
messages: + msg384162
2021-01-01 05:16:27steven.dapranocreate