[Python-checkins] peps: Add short example of using the new API
nick.coghlan
python-checkins at python.org
Sun Dec 30 16:49:11 CET 2012
http://hg.python.org/peps/rev/6926ad909071
changeset: 4644:6926ad909071
user: Nick Coghlan <ncoghlan at gmail.com>
date: Mon Dec 31 01:49:02 2012 +1000
summary:
Add short example of using the new API
files:
pep-0432.txt | 29 +++++++++++++++++++++++++++++
1 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/pep-0432.txt b/pep-0432.txt
--- a/pep-0432.txt
+++ b/pep-0432.txt
@@ -511,6 +511,35 @@
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
------------------------
--
Repository URL: http://hg.python.org/peps
More information about the Python-checkins
mailing list