Add short example of using the new API
This commit is contained in:
parent
501328b348
commit
0a717addf7
29
pep-0432.txt
29
pep-0432.txt
|
@ -511,6 +511,35 @@ All 4 phases will be used by the standard CPython interpreter and the
|
|||
proposed System Python interpreter. Other embedding applications may
|
||||
choose to skip the step of executing code in the ``__main__`` module.
|
||||
|
||||
An embedding application may still continue to leave the second phase
|
||||
entirely under CPython's control by using the existing ``Py_Initialize``
|
||||
API. Alternatively, if an embedding application wants greater control
|
||||
over CPython's initial state, it will be able to use the new, finer
|
||||
grained API, which allows the embedding application greater control
|
||||
over the initialization process::
|
||||
|
||||
/* Phase 1: Pre-Initialization */
|
||||
Py_CoreConfig core_config = Py_CoreConfig_INIT;
|
||||
PyObject *full_config = NULL;
|
||||
/* Easily control the core configuration */
|
||||
core_config.ignore_environment = 1; /* Ignore environment variables */
|
||||
core_config.use_hash_seed = 0; /* Full hash randomisation */
|
||||
Py_BeginInitialization(&core_config);
|
||||
/* Phase 2: Initialization */
|
||||
full_config = PyDict_New();
|
||||
/* Can preconfigure settings here - they will then be
|
||||
* used to derive other settings */
|
||||
Py_ReadConfiguration(full_config);
|
||||
/* Can completely override derived settings here */
|
||||
Py_EndInitialization(full_config);
|
||||
/* Phase 3: Pre-Main */
|
||||
Py_DECREF(full_config);
|
||||
/* If an embedding application has no real concept of a main module
|
||||
* it can leave the interpreter in this state indefinitely.
|
||||
* Otherwise, it can launch __main__ via the Py_Run*AsMain functions.
|
||||
*/
|
||||
|
||||
|
||||
Pre-Initialization Phase
|
||||
------------------------
|
||||
|
||||
|
|
Loading…
Reference in New Issue