This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: PEP 432, PEP 587: Add _Py_RunMain()
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ncoghlan, vstinner
Priority: normal Keywords: patch

Created on 2019-03-29 12:13 by vstinner, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 12618 merged vstinner, 2019-03-29 13:53
Messages (4)
msg339106 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-03-29 12:13
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 ;-)
msg339107 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-03-29 12:24
I'm working on a PR to implement it.
msg339114 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-03-29 14:13
New changeset 2f54908afc5665937d763510b4430f10cf764641 by Victor Stinner in branch 'master':
bpo-36471: Add _Py_RunMain() (GH-12618)
https://github.com/python/cpython/commit/2f54908afc5665937d763510b4430f10cf764641
msg342148 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-05-11 02:06
The PEP 587 will decide if this function is made public or not.
History
Date User Action Args
2022-04-11 14:59:13adminsetgithub: 80652
2019-05-11 02:06:09vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg342148

stage: patch review -> resolved
2019-03-29 14:13:53vstinnersetmessages: + msg339114
2019-03-29 13:53:25vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request12553
2019-03-29 12:24:44vstinnersetmessages: + msg339107
2019-03-29 12:13:44vstinnercreate