Skip to content

sys.exit() does not align with document described behavior since 3.13 #129936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nukemiko opened this issue Feb 10, 2025 · 4 comments
Closed

sys.exit() does not align with document described behavior since 3.13 #129936

nukemiko opened this issue Feb 10, 2025 · 4 comments
Labels
stdlib Python modules in the Lib dir topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error

Comments

@nukemiko
Copy link

nukemiko commented Feb 10, 2025

Bug report

Bug description:

Passing any non-zero integer to sys.exit() causes Python to exit with exit code 1, regardless of the actual value of passed integer. This is inconsistent with the online documentation description, which does not describe or imply this behavior:

The optional argument arg can be an integer giving the exit status (defaulting to zero), or another type of object. If it is an integer, zero is considered “successful termination” and any nonzero value is considered “abnormal termination” by shells and the like.

Reproduced on Python 3.13.1 (provided by Arch Linux), Python 3.13.2 and 3.14.0a4 (both provided by astral-sh/python-build-standalone). Python 3.12 and lower has not affected.

CPython versions tested on:

3.13

Operating systems tested on:

Linux

@nukemiko nukemiko added the type-bug An unexpected behavior, bug, or error label Feb 10, 2025
@hugovk
Copy link
Member

hugovk commented Feb 10, 2025

Cannot reproduce with Python 3.13.2 and Python 3.14.0a4 on macOS, installed using the official installer:

python3.13 --version
Python 3.13.2python3.13 -c "import sys; sys.exit(123)"echo $?
123python3.14 --version
Python 3.14.0a4python3.14 -c "import sys; sys.exit(123)"echo $?
123

Nor with 3.13.0-3.13.2 using uv run 1.py when changing the version in:

# /// script
# requires-python = "==3.13.0"
# ///

import sys
print(sys.version)
sys.exit(123)

Nor with the same script with Ubuntu (via Docker) with 3.13.0-3.13.2 and 3.14.0a4.

@hugovk
Copy link
Member

hugovk commented Feb 10, 2025

Or do you mean the REPL? I can reproduce it with the new REPL in 3.13:

python3.12
Python 3.12.9 (v3.12.9:fdb81425a9a, Feb  4 2025, 12:21:36) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.exit(123)echo $?
123python3.13
Python 3.13.2 (v3.13.2:4f8bb3947cf, Feb  4 2025, 11:51:10) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.exit(123)echo $?
1PYTHON_BASIC_REPL=1 python3.13
Python 3.13.2 (v3.13.2:4f8bb3947cf, Feb  4 2025, 11:51:10) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.exit(123)echo $?
123

@hugovk hugovk added the topic-repl Related to the interactive shell label Feb 10, 2025
@picnixz picnixz added the stdlib Python modules in the Lib dir label Feb 10, 2025
@picnixz
Copy link
Member

picnixz commented Feb 10, 2025

Isn't it a duplicate of #129900?

@picnixz picnixz added the pending The issue will be closed if no feedback is provided label Feb 10, 2025
@hugovk
Copy link
Member

hugovk commented Feb 10, 2025

It is, thanks!

(I knew it looked familiar but couldn't find it when searching!)

@hugovk hugovk closed this as completed Feb 10, 2025
@hugovk hugovk removed the pending The issue will be closed if no feedback is provided label Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants