Message339106
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 ;-) |
|
Date |
User |
Action |
Args |
2019-03-29 12:13:44 | vstinner | set | recipients:
+ vstinner, ncoghlan |
2019-03-29 12:13:44 | vstinner | set | messageid: <1553861624.16.0.982663569767.issue36471@roundup.psfhosted.org> |
2019-03-29 12:13:44 | vstinner | link | issue36471 messages |
2019-03-29 12:13:44 | vstinner | create | |
|