[issue41912] Long generator chain causes segmentation fault

Tim Peters report at bugs.python.org
Fri Oct 2 16:48:44 EDT 2020


Tim Peters <tim at python.org> added the comment:

There is no way in portable ANSI C to deduce a "safe" limit. The limits that exist were picked by hand across platforms, to be conservative guesses at what would "never" break.

You're allowed to increase the limit if you think you know better - and you may! No two platforms are the same. But - again - you do so at your own risk.  There is no bug here unless you can provoke a crash _without_ overriding the default limit.

I was there when the limit was introduced. It was introduced precisely to avoid the vast array of strange system failures that can occur when the C stack overflows - and, again, there is no portable way to detect that "it's getting close" in ANSI C.  Stack sizes provided by platform C implementations are all over the place, from kilobytes to megabytes, and can also be different yet again for threads, and there is no portable way in C to find out what they are.

"""
For my friend using Windows, a value as low as 4000 suffices, which I don't think anyone would argue is unreasonably high.
"""

For the defaults provided by Microsoft's Visual C compiler (which CPython uses), it is unreasonably high - the C stack overflows.  In fact, under the released Python 3.8.5 on my 64-bit Windows, the largest value for which your program isn't obviously broken is about 2512.  If I don't override the default recursion limit on Windows, I cannot provoke a problem with your program on Windows (instead it dies - as designed and intended - with a `RecursionError` exception instead).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41912>
_______________________________________


More information about the Python-bugs-list mailing list