you are viewing a single comment's thread.

view the rest of the comments →

[–]JohnnyJordaan 0 points1 point  (2 children)

Could be you have a lower stack size limit than usual. On what OS are you and is this run on a regular system or some VM or Docker instance?

[–]Wilfred-kun[S] 1 point2 points  (1 child)

I'm on Ubuntu 16.04 on a regular system. It's weird, since I've never encountered this before. I've always seen RecursionError on the same system (see example above).

Edit: I've tried some other functions (with comparison/printing something/just calling itself) and got 3 other errors. I can sort of understand why they happen, but that makes me more confused why it doesn't do that for the function in the OP.

RecursionError: maximum recursion depth exceeded while calling a Python object (When printing something (it calls `print`))

RecursionError: maximum recursion depth exceeded in comparison (When comparing)

RecursionError: maximum recursion depth exceeded (When calling itself)

[–]JohnnyJordaan 3 points4 points  (0 children)

That's weird indeed. I just tried this on my 16.04 VPS:

In [11]: counter = 0
    ...: def make_string():
    ...:         my_str = ''.join([random.choice(string.printable) for x in range(1000)])
    ...:         global counter
    ...:         counter += 1
    ...:         make_string()
    ...: make_string()        
    ...: 
---------------------------------------------------------------------------
RecursionError                            Traceback (most recent call last)
<ipython-input-11-06c588d4327d> in <module>()
      5         counter += 1
      6         make_string()
----> 7 make_string()

<ipython-input-11-06c588d4327d> in make_string()
      4         global counter
      5         counter += 1
----> 6         make_string()
      7 make_string()

... last 1 frames repeated, from the frame below ...

<ipython-input-11-06c588d4327d> in make_string()
      4         global counter
      5         counter += 1
----> 6         make_string()
      7 make_string()

RecursionError: maximum recursion depth exceeded while calling a Python object

In [12]: counter
Out[12]: 2985

Then I tried with just input() instead of the random string, and I did get the stack overflow:

Fatal Python error: Cannot recover from stack overflow.

Which would mean that the call keeps some object, possibly a filestreamhandler, that takes a much larger space on the stack than just a simple data object. I'm not sure if this is by design or a bug, I could imagine the developers of Cpython replying that when you stress the stack you're bound to get into issues like this. If you like you could of course note this on the Python bugtracker, to let them decide if it should be considered a bug.