. Advertisement .
..3..
. Advertisement .
..4..
When executing the program, you tend to receive the process finished with exit code 0. The message also appears in the presence of an IDE for debugging or creating Python applications.
So what is this? Does it affect the overall performance of your program?
This post will give a full answer for this question.
What Is Exit Code 0?
Running any code causes your console ending with Process finished with exit code 0. Here is an example:
pydev debugger: process 21021 is connecting
Connected to pydev debugger (build 131.618)
Process finished with exit code 0
If you receive this message, it means that your code has no error and runs perfectly. Python returns 0 when there is no error existing in the output.
How To Terminate A Python Script With Exit Code 0?
After successfully running the code, you have to terminate the program before the integreter. That’s where exit(0) and exit(1) come in handy.
The functions allow users to come out of the loop immediately and automatically.
Code:
diameter = [4878,12104,6787,142984,120536,51118,49528]
for diameter_of_planet in diameter:
if diameter_of_planet > 12756:
print(diameter_of_planet,'\nThis planet is more giant than Earth')
exit(0)
Output:
142984
This planet is more giant than Earth
Process finished with exit code 0. The above code stopped the program’s execution when the number reached the required condition. In this case, the program will automatically terminate.
The above code reaches the given condition and automatically stops execution. The exit(0) function makes the last two numbers not printed.
The same process will happen with the call exit(1). Your executing program stops before the code completes the loop. This way, it is more straightforward for developers to choose a suitable exit point to avoid confusion or error.
What Is The Difference Between Exit Code 0 And Exit Code 1?
Exit(0) and exit(1) function calls are two Python features revealing a program termination’s status. As mentioned above, the call exit(0) notifies you of a successful program execution.
What if you receive the exit(1) message instead of the exit(0)? This function indicates there is an occurring error. It results from an invalid reference or an application error.
The former issue is an image’s file reference that runs the container. Yet, this container directs to a non-existent file, leading to the terminated container.
On the other hand, the latter is a programming error running within the container. If a Java library throws a compiler error, the container will terminate with Exit Code 1.
Code:
diameter = [4878,12104,6787,142984,'Neptune',120536,51118,49528]
for diameter_of_planet in diameter:
if type(diameter_of_planet) != int :
print('Here is not a diameter value of the planet')
exit(1)
print(diameter_of_planet)
Output:
4878
12104
6787
142984
Here is not a diameter value of the planet
If you run into this problem, it would be best to delete and create the container again. This way, you can clean out transient conditions and all temporary files. Refresh the file system using kubectl run [pod-name] –image=[image-name].
You can also bash into a container to troubleshoot this problem. Use the docker run -ti –rm ${image} /bin/bash command to quickly solve it.
Conclusion
When running the code, there are two scenarios. You may get the exit(0) and exit(1) messages. If you receive the Process finished with exit code 0, don’t worry, there is no problem with your program’s performance.
If Python returns the reverse, check the post to explore what it is and how to solve it.
Leave a comment