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: Python 3.7 does not catch infinite recursion for some values of sys.getrecursionlimit()
Type: crash Stage: resolved
Components: Interpreter Core Versions: Python 3.7
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: Mark.Shannon, Valentyn Tymofieiev, brett.cannon, iritkatriel
Priority: normal Keywords:

Created on 2019-10-25 21:51 by Valentyn Tymofieiev, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (5)
msg355389 - (view) Author: Valentyn Tymofieiev (Valentyn Tymofieiev) Date: 2019-10-25 21:51
While investigating an issue[1] in Apache Beam, we observed that Python 3.7 does not catch an infinite recursion for some values of sys.getrecursionlimit().

Repro steps:

docker run -it --entrypoint=/bin/bash python:3.7-stretch
git clone https://github.com/tvalentyn/beam.git
cd beam
git checkout origin/reproduce_uncaught_recursion_error
cd sdks/python
pip install nose
pip install -e .[gcp,test]
python ./setup.py nosetests --nocapture --tests 'apache_beam/runners/dataflow/dataflow_runner_test.py:DataflowRunnerTest.test_remote_runner_display_data'

On Python 3.7, the test output is:

==========
Recursion limit set to: 1002
Caught maximum recursion depth exceeded while calling a Python object. Current recursionlimit is 1002
Recursion limit set to: 1003
Caught maximum recursion depth exceeded. Current recursionlimit is 1003
Recursion limit set to: 1004
Caught maximum recursion depth exceeded while calling a Python object. Current recursionlimit is 1004
Recursion limit set to: 1005
Caught maximum recursion depth exceeded while calling a Python object. Current recursionlimit is 1005
Recursion limit set to: 1006
Fatal Python error: Cannot recover from stack overflow.

Current thread 0x00007fd9f28a5700 (most recent call first):
  File "/usr/local/lib/python3.7/site-packages/dill/_dill.py", line 424 in get
...
==========

So, if we set recursion limit to 1006 in [2], Python 3.7 interpreter does not throw/catch RecursionError in [3]. On Python 3.5, 3.6 the same code successfully catches RecursionError.  
 
[1] https://issues.apache.org/jira/browse/BEAM-8397 
[2] https://github.com/tvalentyn/beam/blob/158cc9006fef74fc17d52a4220172758f7a82820/sdks/python/apache_beam/runners/dataflow/dataflow_runner_test.py#L235 
[3] https://github.com/tvalentyn/beam/blob/158cc9006fef74fc17d52a4220172758f7a82820/sdks/python/apache_beam/pipeline.py#L599
msg355397 - (view) Author: Valentyn Tymofieiev (Valentyn Tymofieiev) Date: 2019-10-26 01:26
I observed this issue in Python 3.7.2, 3.7.4, 3.7.5, however it seems to be fixed in 3.8.0.
msg355570 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2019-10-28 17:15
Can you provide a small reproducer? Otherwise the recursion check is mostly best effort if you have recursion in C code which never goes out to Python code where the recursion check is implemented.
msg360067 - (view) Author: Valentyn Tymofieiev (Valentyn Tymofieiev) Date: 2020-01-15 17:26
The stack is fairly deep here, and I didn't have time to filter out the smallest repro. 

Since this check is best effort, and not reproducible on the 3.8, perhaps this is a low-priority issue.

Thanks.
msg393882 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-05-18 16:38
3.7 is no longer getting bugfixes.
History
Date User Action Args
2022-04-11 14:59:22adminsetgithub: 82774
2021-05-18 16:38:31iritkatrielsetstatus: open -> closed

nosy: + iritkatriel
messages: + msg393882

resolution: out of date
stage: resolved
2021-02-13 00:03:37iritkatrielsetnosy: + Mark.Shannon
2020-01-15 17:26:12Valentyn Tymofieievsetnosy: + brett.cannon
messages: + msg360067
2019-11-27 18:42:35brett.cannonsetnosy: - brett.cannon
2019-10-28 17:15:46brett.cannonsetnosy: + brett.cannon
messages: + msg355570
2019-10-26 01:26:57Valentyn Tymofieievsetmessages: + msg355397
2019-10-25 21:51:35Valentyn Tymofieievsettype: crash
2019-10-25 21:51:08Valentyn Tymofieievcreate