cpython icon indicating copy to clipboard operation
cpython copied to clipboard

Exit codes are lost in the REPL

Open jleedev opened this issue 1 year ago • 1 comments

Bug report

Bug description:

Python's new REPL seems to eat exit codes and instead return 1:

 ¶ python
Python 3.13.0 (main, Oct 19 2024, 04:14:02) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit(42)
👉      1
 ¶ PYTHON_BASIC_REPL=1 python
Python 3.13.0 (main, Oct 19 2024, 04:14:02) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit(42)
👉      42
 ¶ python -m _pyrepl
>>> exit(42)
👉      42

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs

  • gh-125890

jleedev avatar Oct 23 '24 14:10 jleedev

Hello! Thanks for the report. Confirmed on current main as well. 3.12 behavior:

admin@Admins-MacBook-Air ~/p/cpython (main)> python3.12
Python 3.12.7 (main, Oct  1 2024, 02:05:46) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit(128)
admin@Admins-MacBook-Air ~/p/cpython (main) [128]>

Eclips4 avatar Oct 23 '24 15:10 Eclips4

@ambv @bedevere-bot's fix works great on my Mac. MacOS latest.

╭─cpatti at rocinante in ~/src/personal/cpython on fix-exit-codes✔ 25-05-19 - 16:48:27
╰─⠠⠵ ./python.exe                                                       <region:us-east-1>
Python 3.14.0a1+ (heads/fix-exit-codes:4b65e1aac4d, May 19 2025, 16:48:17) [Clang 17.0.0 (clang-1700.0.13.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit(42)
╭─cpatti at rocinante in ~/src/personal/cpython on fix-exit-codes✔ 25-05-19 - 16:50:43
╰─⠠⠵ echo $?                                                            <region:us-east-1>
42
╭─cpatti at rocinante in ~/src/personal/cpython on fix-exit-codes✔ 25-05-19 - 16:50:46
╰─⠠⠵ ./python.exe                                                       <region:us-east-1>
Python 3.14.0a1+ (heads/fix-exit-codes:4b65e1aac4d, May 19 2025, 16:48:17) [Clang 17.0.0 (clang-1700.0.13.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit(56)
╭─cpatti at rocinante in ~/src/personal/cpython on fix-exit-codes✔ 25-05-19 - 16:51:32
╰─⠠⠵ echo $?                                                            <region:us-east-1>
56
╭─cpatti at rocinante in ~/src/personal/cpython on fix-exit-codes✔ 25-05-19 - 16:51:35
╰─⠠⠵ python -m _pyrepl                                                  <region:us-east-1>
╭─cpatti at rocinante in ~/src/personal/cpython on fix-exit-codes✔ 25-05-19 - 16:51:47
╰─⠠⠵ ./python.exe -m _pyrepl                                            <region:us-east-1>
>>> exit(42)
╭─cpatti at rocinante in ~/src/personal/cpython on fix-exit-codes✔ 25-05-19 - 16:51:56
╰─⠠⠵ echo $?                                                            <region:us-east-1>
42

feoh avatar May 19 '25 20:05 feoh