Skip to content

C API: No longer exit Python in Py_InitializeFromConfig() #158080

Description

@vstinner

When PEP 587 "Python Initialization Configuration" (PyConfig C API) has been implemented, the code to initialize Python was scattered in many places, and it was a tedious task to move all options to the new PyConfig structure.

The PyConfig structure has a wart that I always hated: Py_InitializeFromConfig() can fail with an exit code. It requires the caller to handle this special case: "Python wants to exit".

I propose moving the processing of command line options which want to exit Python: process these options in Py_RunMain() instead. So Py_InitializeFromConfig() can no longer exit with an "exit status": PyStatus_IsExit(status) is always false.

Py_RunMain() return value is an exit code, so it's more natural to process the command line options there.

PEP 741 "Python Configuration C API" just inherited its "exit status" from PyConfig in PyInitConfig. If we fix Py_InitializeFromConfig(), Py_InitializeFromInitConfig() will be fixed as well.

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions