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.

Author vstinner
Recipients ncoghlan, vstinner
Date 2019-03-29.12:13:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1553861624.16.0.982663569767.issue36471@roundup.psfhosted.org>
In-reply-to
Content
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 ;-)
History
Date User Action Args
2019-03-29 12:13:44vstinnersetrecipients: + vstinner, ncoghlan
2019-03-29 12:13:44vstinnersetmessageid: <1553861624.16.0.982663569767.issue36471@roundup.psfhosted.org>
2019-03-29 12:13:44vstinnerlinkissue36471 messages
2019-03-29 12:13:44vstinnercreate