On 19/01/2021 2:38 pm, Terry Reedy wrote:
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.
I'm not sure whether you are saying that this doesn't work now, that it can't work, or that it shouldn't work. If that it doesn't work now, then I agree. That's why I've written the PEP; it should work. If either of the other two, why? Cheers, Mark.