You're looking for calls to sys.exit(...) (exit(...) calls sys.exit(...)) in the script. The argument to that method is returned to the environment as the exit code.

It's fairly likely that the script is never calling the exit(...) method, and that 0 is the default exit code.

Answer from Dave Costa on Stack Overflow
🌐
Linux Hint
linuxhint.com › python-exit-codes
Python Exit Codes – Linux Hint
We can see that the program does return the desired output. On Unix systems, we can use the echo command followed by the environment variable ?. This environment variable allows you to get the exit code of the last executed command. In our case, the last command is the Python program:
Discussions

Return codes - Is there a list of them?
The meaning of the return codes for a process are decided by the program that returned it. There are some very limited conventions on Unix: https://stackoverflow.com/questions/1101957/are-there-any-standard-exit-status-codes-in-linux , but these are not at all universal. You can't rely upon it unless you know the specific program you're running conforms to it. And at any rate it covers very few of the possible exits. More on reddit.com
🌐 r/learnpython
4
1
January 12, 2025
unix - Python exit codes - Stack Overflow
Where can I find information about meaning of exit codes of "python" process on Unix? For instance, if I do "python thisfiledoesntexist.py", I get exit code 2 Summary: from errno import errorcode... More on stackoverflow.com
🌐 stackoverflow.com
KeyboardInterrupt and SystemExit in exception groups should be considered for Python's exit code - Ideas - Discussions on Python.org
I’ll start with an example program to try to show what I think is a pitfall. Then I’ll be more specific. ▶ Example program I think that a KeyboardInterrupt or a SystemExit within an exception group should behave as if those exceptions weren’t in an exception group with regards to the ... More on discuss.python.org
🌐 discuss.python.org
0
March 3, 2025
Pycharm Exit Code

This code looks like a Access violation error. Without any code we can't help you, but most of the time you tried to read an incorrect part of a file, maybe the GeoJSON file is corrupted or you need to use the correct encoding.

More on reddit.com
🌐 r/Python
2
1
October 8, 2019
🌐
Notes
henryleach.com › 2025 › 02 › controlling-python-exit-codes-and-shell-scripts
Controlling Python Exit Codes and Shell Scripts - Henry Leach
February 9, 2025 - $ python exit-examples.py; echo Returned $? Hello World Returned 1 · You could of course return any value you like between 0 and 255, but other than 0 being success, there's not much agreement what the various exit codes mean. On Linux there are some reserved exit codes, and the FreeBSD sysexits(3) list ...
🌐
The Linux Documentation Project
tldp.org › LDP › abs › html › exitcodes.html
Appendix E. Exit Codes With Special Meanings
According to the above table, exit codes 1 - 2, 126 - 165, and 255 [1] have special meanings, and should therefore be avoided for user-specified exit parameters. Ending a script with exit 127 would certainly cause confusion when troubleshooting (is the error code a "command not found" or a ...
🌐
pytest
docs.pytest.org › en › stable › reference › exit-codes.html
Exit codes - pytest documentation
They are represented by the pytest.ExitCode enum. The exit codes being a part of the public API can be imported and accessed directly using:
🌐
GeeksforGeeks
geeksforgeeks.org › python-exit-commands-quit-exit-sys-exit-and-os-_exit
Python exit commands: quit(), exit(), sys.exit() and os._exit() - GeeksforGeeks
December 31, 2019 - The functions quit(), exit(), sys.exit() and os._exit() have almost same functionality as they raise the SystemExit exception by which the Python interpreter exits and no stack traceback is printed. We can catch the exception to intercept early exits and perform cleanup activities; if uncaught, the interpreter exits as usual. When we run a program in Python, we simply execute all the code in file, from top to bottom.
🌐
Delft Stack
delftstack.com › home › howto › python › exit codes in python
How to Exit Codes in Python | Delft Stack
March 11, 2025 - Learn how to manage exit codes in Python effectively, especially in the context of Git hooks. This article covers the importance of exit codes, how to implement them in your scripts, and best practices for using them in Git operations. Enhance your coding skills and improve your workflow with ...
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › return codes - is there a list of them?
r/learnpython on Reddit: Return codes - Is there a list of them?
January 12, 2025 -

I was using subprocess.run and needed to understand the return codes. Problem is I haven't been able to find a list of them. Python docs seem to be of little help as far as I can find.

Does anyone know of a list and maybe a range of return codes for other functions as well?

Much appreciated.

Edit: Mystery \ Misunderstanding SOLVED... Thanks.

🌐
Super Fast Python
superfastpython.com › home › tutorials › process exit codes in python
Process Exit Codes in Python - Super Fast Python
September 11, 2022 - You can set an exit code for a process via sys.exit() and retrieve the exit code via the exitcode attribute on the multiprocessing.Process class. In this tutorial you will discover how to get and set exit codes for processes in Python. Let’s get started. Need Process Exit Codes A process is a running instance of […]
🌐
GitHub
github.com › sixty-north › exit-codes › blob › master › exit_codes › exit_codes.py
exit-codes/exit_codes/exit_codes.py at master · sixty-north/exit-codes
"""Exit status codes. · Note: If the Enum library is available (Python 3.4+) or backports to · earlier versions, ExitCodes will be an IntEnum, otherwise · ExitCodes will be a regular class with integer class attributes. · These mimic those on many Unixes (and provided by `os`) but make them ·
Author   sixty-north
🌐
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 - Note: If you pass anything other than an integer to sys.exit() call, the passed value will be printed and system exit status will be 1 . Refer the below example: ... Since exception is properly handled in python code, it will exit with a success return code 0 when Exceptions.sh is executed.
🌐
GitHub
github.com › sixty-north › exit-codes
GitHub - sixty-north/exit-codes: Platform-independent exit codes for Python
from exit_codes import ExitCode def main(): if big_operation(): # If your program exits normally, return OK return ExitCode.OK else: # Otherwise, return the appropriate error code return ExitCode.IO_ERR
Author   sixty-north
🌐
Python Morsels
pythonmorsels.com › exiting-a-python-program
Exiting a Python program - Python Morsels
February 21, 2022 - If you want to exit a Python program early, call the sys.exit function or raise a SystemExit exception. If you're trying to indicate an error code while exiting, pass a number from 0 to 127 to sys.exit, where 0 indicates success and anything else indicates an error.
🌐
Codecademy
codecademy.com › article › python-exit-commands-quit-exit-sys-exit-os-exit-and-keyboard-shortcuts
Python Exit Commands: quit(), exit(), sys.exit(), os._exit() and Keyboard Shortcuts | Codecademy
This function prints numbers from 1 to 20 but exits gracefully when it reaches 10, returning a status code of 0 (indicating successful completion). While sys.exit() ensures proper handling, os._exit() is a lower-level function that forces immediate termination without executing cleanups. Let’s examine it next. When a Python program needs to terminate instantly, bypassing all cleanup routines and exception handling, os._exit() is the go-to command.
🌐
Quora
quora.com › What-is-the-exit-status-code-of-a-Python-script
What is the exit status code of a Python script? - Quora
Answer (1 of 2): In Python, you can check the exit code of a script using the `sys.exit()` function provided by the `sys` module. By default, if your script runs without any issues, it will have an exit code of 0 (zero), which indicates success . The exit codes only have meaning as assigned by th...
🌐
GitHub
hsf-training.github.io › hsf-training-cicd › 02-enter-sandman › index.html
Exit Codes – Continuous Integration / Continuous Development (CI/CD)
September 4, 2025 - and then make it executable chmod +x python_exit.py. Now, try running it with ./python_exit.py hello and ./python_exit.py goodbye and see what those exit codes are.
🌐
Piccolo-orm
piccolo-orm.com › blog › understanding-sys-exit
Understanding sys.exit - Piccolo Blog
April 21, 2021 - On the command line, you can see the exit code of the last command using echo $?. >>> python successful_script.py >>> echo $? 0 >>> python failing_script.py >>> echo $? 1
🌐
Cisco
orbital.amp.cisco.com › help › Content › Topics › Script-Exit-Codes.htm
Script Exit Codes - Orbital
Script exit codes inform Orbital whether a Python script completed successfully. Scripts return an exit code using the sys.exit() function. A zero (0) will be returned if the script completes successfully. A non-zero exit code will be returned if the script fails. For example: ... If a script fails, it will be identified as returning an error in the results listing...
🌐
Python.org
discuss.python.org › ideas
KeyboardInterrupt and SystemExit in exception groups should be considered for Python's exit code - Ideas - Discussions on Python.org
March 3, 2025 - I’ll start with an example program to try to show what I think is a pitfall. Then I’ll be more specific. ▶ Example program I think that a KeyboardInterrupt or a SystemExit within an exception group should behave as if those exceptions weren’t in an exception group with regards to the ...