Skip to content

SystemExit raised by PYTHONSTARTUP can prevent the REPL from starting #143023

@johnslavik

Description

@johnslavik

Bug report

Bug description:

To reproduce:

  1. The new REPL
❯ PYTHONSTARTUP=<(echo 'raise SystemExit') ./python
Python 3.15.0a3+ (heads/main:5b5263648f2, Dec 20 2025, 07:19:41) [GCC 15.2.1 20250808 (Red Hat 15.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
  1. The basic REPL
❯ PYTHON_BASIC_REPL=1 PYTHONSTARTUP=<(echo 'raise SystemExit') ./python
Python 3.15.0a3+ (heads/main:5b5263648f2, Dec 20 2025, 07:19:41) [GCC 15.2.1 20250808 (Red Hat 15.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.

(both actually hit the same code path -- Py_RunMain -> pymain_run_python -> pymain_run_stdin -> pymain_run_startup -> _PyRun_SimpleFileObject -> PyErr_Print -> PyErr_PrintEx -> _PyErr_PrintEx -> handle_system_exit)

While this is largely an edge case of the regular REPLs, copying this semantics just feels wrong in Python code.
I've run into this while adding PYTHONSTARTUP exception handling to the asyncio REPL in GH-140288.

Should I be keeping asyncio REPL in parity with Python-side REPLs behavior in this regard?
Do we want to fix this in the C code?

And lastly, as part of this issue we would document the exception handling of PYTHONSTARTUP.

@ZeroIntensity stdlib interpreter-core docs topic-repl 3.13 3.14 3.15

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions