Skip to content

Defer _PyRuntime_Initialize to Py_InitializeFromConfig. #148790

@AraHaan

Description

@AraHaan

When I was working on my own copy of Py_Initialize() for my own embedded interpreter that:

  • manually sets sys.path (set to the base name of the exe since I store the python stlib in a zip file in it's win32 resource section)
  • Disables the default explicit import site (set to 0)
  • prevents the user site-packages folder from being added (set to 0),

The way I did this was with a direct copy and paste of the code in Py_InitializeEx and changed a only what I needed to implement my own Py_Initialize that suited my own needs. I hated how I needed to define Py_BUILD_CORE_MODULE and include #include <internal/pycore_runtime.h> And then checked and saw that everything but the if check in Py_InitializeEx is inside of Py_InitializeFromConfig and that the if check could be replaced easily with Py_IsInitialized. Because of that I submitted this change to remove the needless code duplication here since Py_InitializeFromConfig is used anyways. It also might increase performance very slightly as a result as well for free.

Because this is a trivial change to an implementation detail and does not affect functionality at all, I feel like this might not need an issue first. Very glad I took the time to look at this code and seen that it could be simplified somewhat.

Issue Created from #121628 as I forgot to file an issue for it a long time ago after opening the PR.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions