0 and 1 are the exit codes.

exit(0) means a clean exit without any errors / problems

exit(1) means there was some issue / error / problem and that is why the program is exiting.

This is not Python specific and is pretty common. A non-zero exit code is treated as an abnormal exit, and at times, the error code indicates what the problem was. A zero error code means a successful exit.

This is useful for other programs, shell, caller etc. to know what happened with your program and proceed accordingly.

Answer from manojlds on Stack Overflow
Discussions

error code 1
Provide the error. Error code 1 means there was an error. Error code 0 means no error. So far we don’t have enough info. More on reddit.com
🌐 r/learnpython
8
0
February 13, 2023
python - What does "Process finished with exit code 1" mean? - Stack Overflow
The effect of each of these codes ... but with Python should be fairly consistent. ... Sign up to request clarification or add additional context in comments. ... exit code (0) means an exit without an errors or any issues, can be a compile time error or any dependency issue. exit code (1) means there ... More on stackoverflow.com
🌐 stackoverflow.com
ubuntu - Systemd - Python script - Main process exited, code=exited, status=1/FAILURE - Unix & Linux Stack Exchange
Aug 22 16:54:13 ip-172-31-13-245 ... systemd[1]: CATALOG_REST-py.service: Failed with result 'exit-code'. I want to say that if I run in terminal python3 /home/GreenHouse/Catalog/Catalog_REST.py , it works. Do you know some ways to obtain a better explanation of the error... More on unix.stackexchange.com
🌐 unix.stackexchange.com
August 22, 2021
Is it better to quit a script due to a user input error using sys.exit(1) or raise Error()?
I think that's just a style decision; I don't think there is a best practice for that. Personally I'd use the raise option, probably because I like to think people use my scripts in their scripts, and the raise option allows them to catch it easier. More on reddit.com
🌐 r/learnpython
6
1
December 9, 2022
🌐
Python Guides
pythonguides.com › command-errored-out-with-exit-status-1-python
How to Fix Command Errored Out With Exit Status 1 in Python
December 22, 2025 - The “exit status 1” is basically Python’s way of saying, “I tried to do what you asked, but it failed, and I don’t have a specific error code for it.”
🌐
Linux Hint
linuxhint.com › python-exit-codes
Python Exit Codes – Linux Hint
Python has only two standard codes, i.e., a one and a zero. The exit code of 0 means that the process has been executed and exited successfully. This means no error was encountered. On the other hand, an error code of 1 indicates that the process exited with a failure.
🌐
Ask Ubuntu
askubuntu.com › questions › 1300198 › run-python-script-return-exit-code-1-as-service-ubuntu
Run python script return exit code =1 as service Ubuntu - Ask Ubuntu
I follow this tutorial ...-to-setup-python-script-autorun-in-ubuntu-18-04/ ... Thg 12 15 11:42:50 thao-HP-ZBook-15 systemd[1]: Started Test Service. Thg 12 15 11:42:50 thao-HP-ZBook-15 systemd[1]: job_tracking.service: Main process exited, code=exited, status=1/FAILURE Thg 12 15 11:42:50 thao-HP-ZBook-15 systemd[1]: job_tracking.service: Failed with result ...
🌐
Medium
medium.com › @anupkumarray › working-with-exit-codes-between-python-shell-scripts-177931204291
Working with exit codes between Python & Shell Scripts | by Anup Kumar Ray | Medium
October 17, 2021 - Standard exit codes are received when python program executes. Successful execution returns 0 and unsuccessful execution returns 1 · Custom exit codes can be passed using sys.exit() call in python. Useful when attaching error descriptions to exit codes.
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › error code 1
r/learnpython on Reddit: error code 1
February 13, 2023 -

So im pretty new to python and im trying to make a chat bot so I try installing chatter bot and I get error code 1 Running setup.py install for preshed did not run successfully. what does this mean and how do I fix it? I tried looking it up but people use lingo I dont know yet. Can anyone tell me how to fix this? that would be great thanks!

🌐
Python Morsels
pythonmorsels.com › exiting-a-python-program
Exiting a Python program - Python Morsels
February 21, 2022 - So let's exit our program with exit code 1 instead: if not args.path.is_dir(): print(f"{args.path} is not a directory") sys.exit(1) As expected, our command prompt doesn't print Success this time: $ python3 fixme.py /home/unicorn && echo "Success" /home/unicorn is not a directory · Whenever you're trying to exit your program while indicating that an error occurred, call sys.exit with a number besides 0.
🌐
Delft Stack
delftstack.com › home › howto › python › exit codes in python
How to Exit Codes in Python | Delft Stack
March 11, 2025 - If black finds formatting issues, it exits with a non-zero code, and the script prints a message and exits with 1, preventing the commit. If everything is fine, it exits with 0, allowing the commit to proceed.
🌐
Oreate AI
oreateai.com › blog › understanding-exit-code-1-what-it-means-for-your-python-programs › 5694cf6ba63410eba2a2c858848c7081
Understanding Exit Code 1: What It Means for Your Python Programs - Oreate AI Blog
December 19, 2025 - Here are some common reasons why you might see exit code 1: Unhandled Exceptions: If your program throws an exception that isn’t caught by any try-except block, you'll likely end up with this exit status.
🌐
Finxter
blog.finxter.com › home › learn python blog › what’s the difference between exit(0) and exit(1) in python?
What's the Difference Between exit(0) and exit(1) in Python? - Be on the Right Side of Change
September 25, 2021 - If someone notices carefully, the program was unable to deliver a result due to the name error that occurred for the misspelling of the variable ‘Quote’. Hence the process was finished with exit code 1 implying that there were some issues in running the program.
🌐
Designsafe-ci
simcenter-messageboard.designsafe-ci.org › smf › index.php
An error occurred in the Python script, the exit code is 1
An error occurred in the Python script, the exit code is 1 · « previous next » · Print · Pages: [1] Print · Pages: [1] « previous next » · SimCenter Forum » · Research in Natural Hazards Engineering [Archived] » · Regional Hazard Simulation (R2D, rWhale) » ·
🌐
Quora
quora.com › What-is-the-exit-status-code-of-a-Python-script
What is the exit status code of a Python script? - Quora
If your Python script runs successfully, it will always exit with a status code of 0. If there was an unhandled exception, it will exit with a status code of 1.
🌐
Stack Exchange
unix.stackexchange.com › questions › 665768 › systemd-python-script-main-process-exited-code-exited-status-1-failure
ubuntu - Systemd - Python script - Main process exited, code=exited, status=1/FAILURE - Unix & Linux Stack Exchange
August 22, 2021 - [Unit] Description=Test Service After=network.target [email protected] [Service] Type=simple ExecStart=/usr/bin/python3 /home/ubuntu/GreenHouse/Catalog/Catalog_REST.py StandardInput=tty-force [Install] WantedBy=multi-user.target ... ● CATALOG_REST-py.service - Test Service Loaded: loaded (/lib/systemd/system/CATALOG_REST-py.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Sun 2021-08-22 16:54:13 UTC; 1s ago Process: 23968 ExecStart=/usr/bin/python3 /home/GreenHouse/Catalog/Catalog_REST.py (code=exited, status=1/FAILURE) Main PID: 23968 (code=exited, status=1/FAILURE) Aug 22 16:54:13 ip-172-31-13-245 systemd[1]: Started Test Service.
🌐
Reddit
reddit.com › r/learnpython › is it better to quit a script due to a user input error using sys.exit(1) or raise error()?
r/learnpython on Reddit: Is it better to quit a script due to a user input error using sys.exit(1) or raise Error()?
December 9, 2022 -

Let's say you have a script that is a simple csv parser but the user enters an invalid filepath for the csv.

Is it better to exit the script with a print("wrong filepath") and then sys.exit(1) or by using raise SomeError("wrong filepath")?

From what I read sys.exit(1) raises an exception also, but it doesn't seem to print a traceback like using raise SomeError("wrong filepath") does. So you can just print the message you want the user to see and exit quietly.

If I were to distribute a script like this to public users. What's the better practice?

🌐
Reddit
reddit.com › r/learnpython › sys.exit(1) still not working to make bash script exit
r/learnpython on Reddit: Sys.exit(1) still not working to make bash script exit
March 12, 2022 -

In my python script I have

if failed:
  write_failed(failed, args)
  sys.exit(1)

In the bash script

#!/bin/bash
niche=$1
set e
python2 script.py -n $niche -ma && 
echo ---------------------
python2 script.py -n $niche -rt -rto

I want it to exit if the first line, above the echo, fails but it is still carrying on regardless of if the first one fails.

So how to make it exit if first script call fails?

The if failed condition should be met because it prints the failed accounts as well, above in the code if failed, and that the failed account is printed.

EDIT: Also just tried putting sys.exit(1) outside that condition and run the script and still ignored by bash.