You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python crashes with mutually recursive code #76203
Dear Friends,
It seems that I manage to find a problem with Python ... version 3.6.3
Attached is a PY file designed to solve a puzzle: see function makeGame1
It takes a few seconds to come up with a solution (deep recursive exhaustive search)
if you switch between lines 109 <==> 110 then it restart Python !?!?!?!?! (see below)
The RESTART line means that you ran this in IDLE and that your program crashed the separate (sub)process that was running your code. When IDLE notices this, it starts a new subprocess.
To test whether this is an IDLE-only problem, I ran your code without IDLE.
C:\Users\Terry>python -i -m tem
>>> doFind()
R 6 12
R 12 22
R 21 32
C 10 21
C 13 22
C 16 23
and quickly got the the Windows 'Program has stopped running' box, with no Python error message. Ditto when run on 3.7.0a2.
Since this is not an IDLE issue, I revised the title.
It is possible that this is a duplicate of an existing crash report, but I am not familiar with such at all. With only the standard, non-specific error message, it is hard to search ;-). What OS are you using?
I don't think that we can fix this issue. I suggest to close it as WONTFIX.
sys.setrecursionlimit(3000)
While Python does its best to catch stack overflow, the C implementation of CPython can exhaust the stack memory (8 MB in Linux?) and then crash with a "stack overflow".
I suggest to rewrite your algorithm to reduce the maximum stack depth.
Or maybe try to find a way to extend the maximum size of the stack (is it possible without rebuilding Python?). See for example RLIMIT_STACK of the resource module on Unix.
On linux x86-64 with python 3.6.3 and python 3.7.0a2+ I get a RecursionError: maximum recursion depth exceeded.
The exact memory usage depends on the Python version and maybe compiler flags. We reduce the stack usage in Python 3.7, search for "Stack consumption" in:
Agreed. If you use sys.setrecursionlimit, you're deliberately bypassing Python's safety mechanisms. A crash due to stack overflow shouldn't be considered a bug under these circumstances.
I was going to suggest that this might be a documentation issue, but the existing documentation already looks sufficient to me:
A user may need to set the limit higher when they have a program that
requires deep recursion and a platform that supports a higher limit.
This should be done with care, because a too-high limit can lead to a
crash.
I confirmed that increasing the recursion limit can change recursion behavior on Windows.
>>> deff(): g()
...
>>> defg(): f()
...
>>> f()
With the default limit or 1000 or increase to 3000, I get a recursion error. With the limit set to 10000, I get 'MemoryError: stack overflow'. It is not too surprising that the more complicated code prevents getting even that.
Activity
shamon51 commentedon Nov 14, 2017
Dear Friends,
It seems that I manage to find a problem with Python ... version 3.6.3
Attached is a PY file designed to solve a puzzle: see function makeGame1
----> counter: 11735841 rec depth: 2367
86792-719
72581-938
916-398--
--9378-97
3985-4859
27-2879--
--819-698
937-69782
812-78561
----> counter: 29203691
It takes a few seconds to come up with a solution (deep recursive exhaustive search)
if you switch between lines 109 <==> 110 then it restart Python !?!?!?!?! (see below)
=============================== RESTART: Shell ===============================
Dr. Shimon Cohen
shamon51@gmail.com
shamon51 commentedon Nov 14, 2017
lines 209 <==> 210
ericvsmith commentedon Nov 14, 2017
Can you reproduce this with a much smaller example?
shamon51 commentedon Nov 14, 2017
Not really...
Did you see the "restart" ?
On Nov 14, 2017 2:38 PM, "Eric V. Smith" <report@bugs.python.org> wrote:
ericvsmith commentedon Nov 14, 2017
That's too much code for me to run without analyzing it first. If I have time, I'll look at it.
shamon51 commentedon Nov 14, 2017
Here is another simple example - Simple? the game board ==> is small
see attached PY file
run ==> doFind()
terryjreedy commentedon Nov 18, 2017
The RESTART line means that you ran this in IDLE and that your program crashed the separate (sub)process that was running your code. When IDLE notices this, it starts a new subprocess.
To test whether this is an IDLE-only problem, I ran your code without IDLE.
and quickly got the the Windows 'Program has stopped running' box, with no Python error message. Ditto when run on 3.7.0a2.
Since this is not an IDLE issue, I revised the title.
[-]Python problem - == RESTART: Shell =====[/-][+]Python crashes with mutually recursive code[/+]terryjreedy commentedon Nov 18, 2017
It is possible that this is a duplicate of an existing crash report, but I am not familiar with such at all. With only the standard, non-specific error message, it is hard to search ;-). What OS are you using?
terryjreedy commentedon Nov 18, 2017
I believe I used the 2nd version of kakuru.py.
shamon51 commentedon Nov 18, 2017
Cool, thanks!
On Nov 18, 2017 5:29 AM, "Terry J. Reedy" <report@bugs.python.org> wrote:
terryjreedy commentedon Nov 18, 2017
PS. When you respond by EMail, please delete the quoted message, as it is redundant, on the web page, with the original copy above.
Jesse-Bakker commentedon Nov 18, 2017
On linux x86-64 with python 3.6.3 and python 3.7.0a2+ I get a RecursionError: maximum recursion depth exceeded.
vstinner commentedon Nov 20, 2017
I don't think that we can fix this issue. I suggest to close it as WONTFIX.
While Python does its best to catch stack overflow, the C implementation of CPython can exhaust the stack memory (8 MB in Linux?) and then crash with a "stack overflow".
I suggest to rewrite your algorithm to reduce the maximum stack depth.
Or maybe try to find a way to extend the maximum size of the stack (is it possible without rebuilding Python?). See for example RLIMIT_STACK of the resource module on Unix.
The exact memory usage depends on the Python version and maybe compiler flags. We reduce the stack usage in Python 3.7, search for "Stack consumption" in:
https://vstinner.github.io/contrib-cpython-2017q1.html
mdickinson commentedon Nov 22, 2017
Agreed. If you use sys.setrecursionlimit, you're deliberately bypassing Python's safety mechanisms. A crash due to stack overflow shouldn't be considered a bug under these circumstances.
mdickinson commentedon Nov 22, 2017
I was going to suggest that this might be a documentation issue, but the existing documentation already looks sufficient to me:
From https://docs.python.org/3/library/sys.html#sys.setrecursionlimit
vstinner commentedon Nov 22, 2017
I close the issue for the reasons given in the latest comments. Sorry!
vstinner commentedon Nov 22, 2017
(Oops, must be closed as "wont fix".)
terryjreedy commentedon Nov 22, 2017
I confirmed that increasing the recursion limit can change recursion behavior on Windows.
With the default limit or 1000 or increase to 3000, I get a recursion error. With the limit set to 10000, I get 'MemoryError: stack overflow'. It is not too surprising that the more complicated code prevents getting even that.