Skip to content

PEP 432, PEP 587: Add _Py_RunMain() #80652

Closed

Description

@vstinner
BPO 36471
Nosy @ncoghlan, @vstinner
PRs
  • bpo-36471: Add _Py_RunMain() #12618
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-05-11.02:06:09.001>
    created_at = <Date 2019-03-29.12:13:44.145>
    labels = ['interpreter-core', '3.8']
    title = 'PEP 432, PEP 587: Add _Py_RunMain()'
    updated_at = <Date 2019-05-11.02:06:08.998>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2019-05-11.02:06:08.998>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-05-11.02:06:09.001>
    closer = 'vstinner'
    components = ['Interpreter Core']
    creation = <Date 2019-03-29.12:13:44.145>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36471
    keywords = ['patch']
    message_count = 4.0
    messages = ['339106', '339107', '339114', '342148']
    nosy_count = 2.0
    nosy_names = ['ncoghlan', 'vstinner']
    pr_nums = ['12618']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue36471'
    versions = ['Python 3.8']

    Activity

    1. vstinner commented on Mar 29, 2019

      @vstinner
      MemberAuthor

      The PEP-587 adds new functions taking command line arguments:

      Py_PreInitializeFromArgs(config, argc, argv)
      Py_PreInitializeFromWideArgs(config, argc, argv)
      Py_InitializeFromArgs(config, argc, argv)
      Py_InitializeFromWideArgs(config, argc, argv)

      I propose to add _Py_RunMain() (currently private, until PEP-587 is accepted) to be able to implement something similar to Py_Main() but with way more configuration options:

      Example to create an "isolated Python" in a few line of C:
      ---

      #include <Python.h>
      
      int main(int argc, char *argv[])
      {
          _PyCoreConfig config = _PyCoreConfig_INIT;
          config.isolated = 1;
      
          _PyInitError err = _Py_InitializeFromArgs(&config, argc, argv);
          if (_Py_INIT_FAILED(err)) {
              _Py_ExitInitError(err);
          }
      
          return _Py_RunMain();
      }

      It's like the regular "python3" program, except that it's always isolated:
      ---

      $ my-isolated-python
      Python 3.8.0a3+ (heads/run_main-dirty:d167362ecc, Mar 29 2019, 13:03:30) 
      >>> 1+1
      2
      >>> import sys
      >>> sys.flags.isolated
      1

      Using _Py_RunMain(), it becomes trivial to implement something like PEP-432's "system python" idea ;-)

    2. vstinner commented on Mar 29, 2019

      @vstinner
      MemberAuthor

      I'm working on a PR to implement it.

    3. vstinner commented on Mar 29, 2019

      @vstinner
      MemberAuthor

      New changeset 2f54908 by Victor Stinner in branch 'master':
      bpo-36471: Add _Py_RunMain() (GH-12618)
      2f54908

    4. vstinner commented on May 11, 2019

      @vstinner
      MemberAuthor

      The PEP-587 will decide if this function is made public or not.

    5. transferred this issue fromon Apr 10, 2022
    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

      3.8 (EOL)end of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions