I am at early stage of learning Python. I tried calculating Ackerman function for smaller values. It worked just fine until the values are (3,7). Any value higher than that (say 3,8) throws this error. [Process finished with exit code -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)
You can set an exit code for a process via sys. exit() and retrieve the exit code via the exitcode attribute on the multiprocessing.
Exit code 1 occurs whenever there is an error in our code, but exit code 0 means that there is no error and our code has run entirely without any problem.
"process finished with exit code 0" -! It means that there is no error in your code.
An error code of 2 is usually (not always) file not found. This to me would suggest that your python script isn't correctly picking up the file. Are you using a relative path in your script? As it may be that when you run it from the cmd line you are in a different location and that is why it works.
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. 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.
related question: Process finished with exit code -1073741571
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With