Skip to content

gh-152132: Fix Py_RunMain() to return an exit code#153294

Open
vstinner wants to merge 4 commits into
python:mainfrom
vstinner:pyrun_exitcode
Open

gh-152132: Fix Py_RunMain() to return an exit code#153294
vstinner wants to merge 4 commits into
python:mainfrom
vstinner:pyrun_exitcode

Conversation

@vstinner

@vstinner vstinner commented Jul 7, 2026

Copy link
Copy Markdown
Member

Fix Py_RunMain() to return an exit code, rather than calling Py_Exit(), when running a script, a command, or the REPL.

Changes:

  • Add E_EXITCODE return value to <errcode.h> header.
  • Add exitcode parameter to internal functions: _PyRun_SimpleFile(), _PyRun_AnyFile() and _PyRun_InteractiveLoop().
  • Add unit tests.
  • pymain_repl() now displays the error if PySys_Audit() or import _pyrepl failed.

Fix Py_RunMain() to return an exit code, rather than calling
Py_Exit(), when running a script, a command, or the REPL.

Changes:

* Add E_EXITCODE return value to <errcode.h> header.
* Add exitcode parameter to internal functions: _PyRun_SimpleFile(),
  _PyRun_AnyFile() and _PyRun_InteractiveLoop().
* Add unit tests.
* pymain_repl() now displays the error if PySys_Audit() or import
  _pyrepl failed.
Make sure that Py_RunMain() didn't call Py_Exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant