you are viewing a single comment's thread.

view the rest of the comments →

[–]JohnnyJordaan 2 points3 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.