Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Process finished with exit code -1073741571 (0xC00000FD) in Python

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)
like image 806
Suresh Kumar Avatar asked Jun 24 '20 08:06

Suresh Kumar


People also ask

How do I return an exit code in Python?

You can set an exit code for a process via sys. exit() and retrieve the exit code via the exitcode attribute on the multiprocessing.

What is process finished with exit code 0 in Python?

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.

What does it mean process finished with exit code?

"process finished with exit code 0" -! It means that there is no error in your code.

What is exit code 2 in Python?

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.


1 Answers

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

like image 86
Keray Avatar answered Sep 18 '22 11:09

Keray