Python error message

Discussion in 'Mac Programming' started by rcLrecoil, Jan 4, 2011.

  1. rcLrecoil macrumors newbie

    Jan 4, 2011
    Hi guys, new to the forums, osx and programming, having just started at university and have run into some trouble. I'm creating a program in python that basically simulates a bank teller, moderates the length of the que etc.

    Upon running for longer than a few virtual days it crashes leaving an error message.

    ill paste what i have and the error message below.

    bear in mind the code is not complete, but should be able to run none the less.

    (ignore the end graph) < code < error

    it can be re produced on any computer by running the code and entering more than 5 or 6 days to run.

    does anyone have any idea how i could fix this??

    many thanks.
  2. kpua macrumors 6502

    Jul 25, 2006
    It looks to me like too much recursion.

    Each method invocation requires a frame which is stored in the memory reserved for stack. If your stack gets large enough to use all available stack memory, then any attempts to use additional stack space will fail with an unpredictable crash, like the one you're seeing.

    This kind of crash often occurs with infinite recursion, but given how heavily your program appears to rely heavily on recursion, you may simply be attempting to recurse too much for larger inputs. You might want to try using a simple loop instead.
  3. rcLrecoil thread starter macrumors newbie

    Jan 4, 2011
    awww, that's a shame, i was enjoying my little recursive fest.

    is there anyway to purge the stack every now and then, or allocate more memory or anything like that or is it going to have to be a case of a complete re write?

    thanks for the response.
  4. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    The stack holds important information. If it's purged, you lose information. That isn't something a program usually does intentionally.

    The standard way of avoiding death by recursion is to refactor it so the recursive structure is explicit. That is, implement your own stack. This usually takes less memory than relying on the call stack, but it will still have a recursion limit. It also gives you the control necessary to virtualize it to disk if necessary.

    The other tool to apply is converting tail-recursion to iteration. Search Wikipedia for keywords tail recursion.
  5. lee1210 macrumors 68040


    Jan 10, 2005
    Dallas, TX
  6. rcLrecoil thread starter macrumors newbie

    Jan 4, 2011
    thanks guys

    hi guys, thanks very much for your input, i could not work out how to do that special recursion to save the stack so i re wrote the code in while loops instead and now it's fine.


Share This Page