Skip to content

Python crashes with mutually recursive code #76203

Closed

Description

@shamon51
mannequin
BPO 32022
Nosy @terryjreedy, @mdickinson, @vstinner, @ericvsmith, @Jesse-Bakker
Files
  • KAKURU.py: PY file
  • KAKURU.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2017-11-22.17:52:13.220>
    created_at = <Date 2017-11-14.09:02:41.086>
    labels = ['interpreter-core', '3.7', 'type-crash']
    title = 'Python crashes with mutually recursive code'
    updated_at = <Date 2017-11-22.19:36:30.927>
    user = 'https://bugs.python.org/shamon51'

    bugs.python.org fields:

    activity = <Date 2017-11-22.19:36:30.927>
    actor = 'terry.reedy'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-11-22.17:52:13.220>
    closer = 'vstinner'
    components = ['Interpreter Core']
    creation = <Date 2017-11-14.09:02:41.086>
    creator = 'shamon51'
    dependencies = []
    files = ['47263', '47264']
    hgrepos = []
    issue_num = 32022
    keywords = []
    message_count = 18.0
    messages = ['306190', '306191', '306201', '306202', '306214', '306220', '306469', '306470', '306471', '306473', '306474', '306496', '306568', '306738', '306739', '306741', '306742', '306751']
    nosy_count = 6.0
    nosy_names = ['terry.reedy', 'mark.dickinson', 'vstinner', 'eric.smith', 'shamon51', 'jbakker']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue32022'
    versions = ['Python 3.6', 'Python 3.7']

    Activity

    1. shamon51 commented on Nov 14, 2017

      shamon51mannequin
      MannequinAuthor

      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

      To find a solution run: doFind() 
      >>> doFind()

      ----> 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)

      >> doFind()

      =============================== RESTART: Shell ===============================

      >>

      Dr. Shimon Cohen
      shamon51@gmail.com

    2. added
      interpreter-core
      type-crash
      on Nov 14, 2017
    3. shamon51 commented on Nov 14, 2017

      shamon51mannequin
      MannequinAuthor

      lines 209 <==> 210

    4. ericvsmith commented on Nov 14, 2017

      @ericvsmith
      Member

      Can you reproduce this with a much smaller example?

    5. shamon51 commented on Nov 14, 2017

      shamon51mannequin
      MannequinAuthor

      Not really...
      Did you see the "restart" ?

      On Nov 14, 2017 2:38 PM, "Eric V. Smith" <report@bugs.python.org> wrote:

      Eric V. Smith <eric@trueblade.com> added the comment:

      Can you reproduce this with a much smaller example?

      ----------
      nosy: +eric.smith


      Python tracker <report@bugs.python.org>
      <https://bugs.python.org/issue32022\>


    6. ericvsmith commented on Nov 14, 2017

      @ericvsmith
      Member

      That's too much code for me to run without analyzing it first. If I have time, I'll look at it.

    7. shamon51 commented on Nov 14, 2017

      shamon51mannequin
      MannequinAuthor

      Here is another simple example - Simple? the game board ==> is small
      see attached PY file
      run ==> doFind()

    8. terryjreedy commented on Nov 18, 2017

      @terryjreedy
      Member

      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.

    9. changed the title [-]Python problem - == RESTART: Shell =====[/-] [+]Python crashes with mutually recursive code[/+] on Nov 18, 2017
    10. terryjreedy commented on Nov 18, 2017

      @terryjreedy
      Member

      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?

    11. terryjreedy commented on Nov 18, 2017

      @terryjreedy
      Member

      I believe I used the 2nd version of kakuru.py.

    12. shamon51 commented on Nov 18, 2017

      shamon51mannequin
      MannequinAuthor

      Cool, thanks!

      On Nov 18, 2017 5:29 AM, "Terry J. Reedy" <report@bugs.python.org> wrote:

      Terry J. Reedy <tjreedy@udel.edu> added the comment:

      I believe I used the 2nd version of kakuru.py.

      ----------


      Python tracker <report@bugs.python.org>
      <https://bugs.python.org/issue32022\>


    13. terryjreedy commented on Nov 18, 2017

      @terryjreedy
      Member

      PS. When you respond by EMail, please delete the quoted message, as it is redundant, on the web page, with the original copy above.

    14. Jesse-Bakker commented on Nov 18, 2017

      Jesse-Bakkermannequin
      Mannequin

      On linux x86-64 with python 3.6.3 and python 3.7.0a2+ I get a RecursionError: maximum recursion depth exceeded.

    15. vstinner commented on Nov 20, 2017

      @vstinner
      Member

      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:

      https://vstinner.github.io/contrib-cpython-2017q1.html

    16. mdickinson commented on Nov 22, 2017

      @mdickinson
      Member

      I suggest to close it as WONTFIX.

      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.

    17. mdickinson commented on Nov 22, 2017

      @mdickinson
      Member

      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.

      From https://docs.python.org/3/library/sys.html#sys.setrecursionlimit

    18. vstinner commented on Nov 22, 2017

      @vstinner
      Member

      I close the issue for the reasons given in the latest comments. Sorry!

    19. vstinner commented on Nov 22, 2017

      @vstinner
      Member

      (Oops, must be closed as "wont fix".)

    20. terryjreedy commented on Nov 22, 2017

      @terryjreedy
      Member

      I confirmed that increasing the recursion limit can change recursion behavior on Windows.

      >>> def f(): g()
      ...
      >>> def g(): 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.

    21. transferred this issue fromon Apr 10, 2022
    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

      3.7 (EOL)interpreter-coretype-crash

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions