Skip to content

gh-152132: Fix bugs and enhance Py_RunMain()#153461

Merged
vstinner merged 1 commit into
python:mainfrom
vstinner:pyrun_error
Jul 9, 2026
Merged

gh-152132: Fix bugs and enhance Py_RunMain()#153461
vstinner merged 1 commit into
python:mainfrom
vstinner:pyrun_error

Conversation

@vstinner

@vstinner vstinner commented Jul 9, 2026

Copy link
Copy Markdown
Member
  • Check for signals more often. Previously, a pending exception could be removed by PyErr_Clear().
  • Only call _PyInterpreterState_SetNotRunningMain() if _PyInterpreterState_SetRunningMain() has been called.
  • Add pymain_set_path0() function.
  • Simplify pymain_run_startup(): avoid strerror() which is decoded from the wrong encoding. Instead display the exception, Py_fopen() raises an OSError with the path object.
  • Add pymain_error() and pyrun_error(): write the error message to sys.stderr instead of the C stream stderr.
  • Add _PySys_FormatV() function.
  • Convert _PyPathConfig_UpdateGlobal() PyStatus error to an exception.

* Check for signals more often. Previously, a pending exception could
  be removed by PyErr_Clear().
* Only call _PyInterpreterState_SetNotRunningMain() if
  _PyInterpreterState_SetRunningMain() has been called.
* Add pymain_set_path0() function.
* Simplify pymain_run_startup(): avoid strerror() which is decoded
  from the wrong encoding. Instead display the exception, Py_fopen()
  raises an OSError with the path object.
* Add pymain_error() and pyrun_error(): write the error message to
  sys.stderr instead of the C stream stderr.
* Add _PySys_FormatV() function.
* Convert _PyPathConfig_UpdateGlobal() PyStatus error to an
  exception.
@vstinner vstinner merged commit 1b41c7b into python:main Jul 9, 2026
55 checks passed
@vstinner vstinner deleted the pyrun_error branch July 9, 2026 23:29
vstinner added a commit to vstinner/cpython that referenced this pull request Jul 9, 2026
* Check for signals more often. Previously, a pending exception could
  be removed by PyErr_Clear().
* Only call _PyInterpreterState_SetNotRunningMain() if
  _PyInterpreterState_SetRunningMain() has been called.
* Convert _PyPathConfig_UpdateGlobal() PyStatus error to an
  exception.
vstinner added a commit to vstinner/cpython that referenced this pull request Jul 9, 2026
* Check for signals more often. Previously, a pending exception could
  be removed by PyErr_Clear().
* Only call _PyInterpreterState_SetNotRunningMain() if
  _PyInterpreterState_SetRunningMain() has been called.
* Convert _PyPathConfig_UpdateGlobal() PyStatus error to an
  exception.
@bedevere-app

bedevere-app Bot commented Jul 9, 2026

Copy link
Copy Markdown

GH-153466 is a backport of this pull request to the 3.15 branch.

vstinner added a commit that referenced this pull request Jul 10, 2026
* Check for signals more often. Previously, a pending exception could
  be removed by PyErr_Clear().
* Only call _PyInterpreterState_SetNotRunningMain() if
  _PyInterpreterState_SetRunningMain() has been called.
* Convert _PyPathConfig_UpdateGlobal() PyStatus error to an
  exception.
vstinner added a commit that referenced this pull request Jul 10, 2026
…153468)

[3.15] gh-152132: Fix bugs in Py_RunMain() (GH-153461) (GH-153466)

* Check for signals more often. Previously, a pending exception could
  be removed by PyErr_Clear().
* Only call _PyInterpreterState_SetNotRunningMain() if
  _PyInterpreterState_SetRunningMain() has been called.
* Convert _PyPathConfig_UpdateGlobal() PyStatus error to an
  exception.
(cherry picked from commit cecafeb)

Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner added a commit that referenced this pull request Jul 10, 2026
…153467)

[3.15] gh-152132: Fix bugs in Py_RunMain() (GH-153461) (GH-153466)

* Check for signals more often. Previously, a pending exception could
  be removed by PyErr_Clear().
* Only call _PyInterpreterState_SetNotRunningMain() if
  _PyInterpreterState_SetRunningMain() has been called.
* Convert _PyPathConfig_UpdateGlobal() PyStatus error to an
  exception.
(cherry picked from commit cecafeb)

Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant