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
🌐
Piccolo-orm
piccolo-orm.com › blog › understanding-sys-exit
Understanding sys.exit - Piccolo Blog
April 21, 2021 - The number passed to sys.exit is the exit code. In Unix, an exit code of 1 means something went wrong.
Discussions

Return vs sys.exit()
Consider a program with threads and lots of asynchronous stuff. I have a main where at the end of it somebody has written “sys.exit(0)”. And in catching exceptions at some places there’s sys.exit(1). But I want to return some data at the end of main. If I use return statement above ... More on discuss.python.org
🌐 discuss.python.org
9
0
February 5, 2024
Is sys.exit() bad practice?
In a library that someone else uses, if you call sys.exit, you won't be popular. In your own code, it's manageable however you want to handle it More on reddit.com
🌐 r/Python
64
111
February 13, 2018
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-exit-commands-quit-exit-sys-exit-and-os-_exit
Python exit commands: quit(), exit(), sys.exit() and os._exit() - GeeksforGeeks
July 12, 2025 - If age is 18 or greater, it will print "Age is not less than 18". This code is used to exit the script with a specific message when a certain condition is met. And it stop a program in Python. ... import sys age = 17 if age < 18: sys.exit("Age less than 18") else: print("Age is not less than 18")
🌐
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 ...
🌐
docs.python.org
docs.python.org › 3 › library › sys.html
sys — System-specific parameters and functions
If another type of object is passed, None is equivalent to passing zero, and any other object is printed to stderr and results in an exit code of 1. In particular, sys.exit("some error message") is a quick way to exit a program when an error occurs.
🌐
Hackage
hackage.haskell.org › package › exit-codes-1.0.0 › docs › System-Exit-Codes.html
System.Exit.Codes
These are Haskell values generated by the C pre processor which expose exit codes as defined by the BSD project in "sysexits.h".
Find elsewhere
🌐
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 ...
🌐
Reddit
reddit.com › r/python › is sys.exit() bad practice?
Is sys.exit() bad practice? : r/Python
February 13, 2018 - If your code throws an error and doesn’t exit not zero I hope you stub your toe every day until you die ... My code doesn't have a main(), I, like most employed Python programmers, use a framework. ... Just so you know, Python programs throw error codes that aren't 0 when they fail and 0 when they succeed. You can overwrite that with sys.exit, so yes, it is a C thing.
🌐
Notes
henryleach.com › 2025 › 02 › controlling-python-exit-codes-and-shell-scripts
Controlling Python Exit Codes and Shell Scripts - Henry Leach
February 9, 2025 - Here sys.exit() comes into play, which allows you to control the return value of your program.
🌐
Quora
quora.com › What-is-the-exit-status-code-of-a-Python-script
What is the exit status code of a Python script? - Quora
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 the script author.
🌐
Super Fast Python
superfastpython.com › home › tutorials › exit a process with sys.exit() in python
Exit a Process with sys.exit() in Python - Super Fast Python
September 11, 2022 - The exit code of a process is accessible via the multiprocessing.Process.exitcode attribute. The process exitcode is set automatically, for example: If the process is still running, the exitcode will be None.
🌐
Baeldung
baeldung.com › home › java › core java › a guide to system.exit()
A Guide to System.exit() | Baeldung
January 16, 2024 - We can pass any integer as an argument to the method. A non-zero status code is considered as an abnormal exit. Calling the System.exit method terminates the currently running JVM and exits the program.
🌐
Cisco
orbital.amp.cisco.com › help › Content › Topics › Script-Exit-Codes.htm
Script Exit Codes - Orbital
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.
🌐
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 - On executing the shell script (which calls the python code), we get standard exit code as shown below: ... 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 .
🌐
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 ...
🌐
Linux Hint
linuxhint.com › python-exit-codes
Python Exit Codes – Linux Hint
Take the example program below that returns an exit code of 125. from sys import exit print("Hi!") exit(125) print("Welcome to linuxhint")
🌐
freeCodeCamp
freecodecamp.org › news › python-exit-how-to-use-an-exit-function-in-python-to-stop-a-program
Python Exit – How to Use an Exit Function in Python to Stop a Program
June 5, 2023 - Again, a status code of 0 is typically used to indicate successful program completion, while non-zero values represent different types of errors or exceptional conditions. if condition_met: sys.exit() # Terminate the program with status code 0