[英]Process finished with exit code -1073741571 (0xC00000FD) in Python
I am at early stage of learning Python.我正处于学习 Python 的早期阶段。 I tried calculating Ackerman function for smaller values.
我尝试计算 Ackerman function 以获得较小的值。 It worked just fine until the values are (3,7).
它工作得很好,直到值为(3,7)。 Any value higher than that (say 3,8) throws this error.
任何高于此的值(例如 3,8)都会引发此错误。 [Process finished with exit code -1073741571 (0xC00000FD)]
[进程以退出代码 -1073741571 (0xC00000FD) 结束]
At first I checked whether recursion limit is reached, but the process stopped well below the set Recursion limit (in this case it is set to maximum)起初我检查是否达到递归限制,但进程停止在远低于设置的递归限制(在这种情况下,它设置为最大值)
import sys
sys.setrecursionlimit(999999999)
count = 0
def cf():
global count
count+=1
cf()
def Ack(m,n):
if m==0:
x=n+1
cf()
return x
elif m>0 and n==0:
x=Ack(m-1,1)
cf()
return x
elif m>0 and n>0:
x=Ack(m-1,Ack(m,n-1))
cf()
return x
a,b=map(int,input("Enter values").split())
print(a,b)
result=Ack(a,b)
print(result)
print(count)
Simple as that, you are getting a stack overflow.就这么简单,你得到了堆栈溢出。
Recursion limit only dictates how deep the recursion calls can go, but it doesn't change the stack size.递归限制仅指示递归调用 go 的深度,但它不会更改堆栈大小。 Each recursive call adds frames to the stack and eventually you are reaching the limit.
每个递归调用都会将帧添加到堆栈中,最终您会达到限制。
If you really want to go so deep with recursion, you have to change stack size with threading.stack_size()
and create a new thread.如果你真的想要 go 这么深的递归,你必须用
threading.stack_size()
改变堆栈大小并创建一个新线程。
related question: Process finished with exit code -1073741571相关问题: 进程以退出代码 -1073741571 结束
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.