On 1/19/2021 8:31 AM, Mark Shannon wrote:
Hi everyone,
It's time for yet another PEP :)
Fortunately, this one is a small one that doesn't change much.
It's aim is to make the VM more robust.
Abstract
========
This PEP proposes that machine stack overflow is treated differently
from runaway recursion. This would allow programs to set the maximum
recursion depth to fit their needs and provide additional safety
guarantees.
The following program will run safely to completion:
sys.setrecursionlimit(1_000_000)
def f(n):
if n:
f(n-1)
f(500_000)
Are you sure? On Windows, after adding the import
and a line at the top of f
if not n % 1000: print(n)
I get with Command Prompt
C:\Users\Terry>py -m a.tem4
500000
499000
498000
C:\Users\Terry>
with a pause of after 1 to multiple seconds. Clearly did not run to
completion, but no exception or Windows crash box to indicate such
without the print.
In IDLE, I get nearly the same:
========================= RESTART: F:\Python\a\tem4.py
500000
499000
498000
================================ RESTART: Shell
>>>
The Shell restart indicates that the user code subprocess crashed and
was restarted. I checked that sys.getrecursionlimit() really returns
1_000_000.
To show completion, do something like add global m and m+=1 in f and m=0
and print(m) after the f call.
--
Terry Jan Reedy
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/KNWNOKK3QJVS3DCHNY3FOFSVMVU3EVMA/
Code of Conduct: http://python.org/psf/codeofconduct/