2012-12-27 09:41:16 -05:00
|
|
|
PEP: 432
|
2016-12-31 02:07:04 -05:00
|
|
|
Title: Restructuring the CPython startup sequence
|
2012-12-27 09:41:16 -05:00
|
|
|
Version: $Revision$
|
|
|
|
Last-Modified: $Date$
|
2023-10-11 08:05:51 -04:00
|
|
|
Author: Alyssa Coghlan <ncoghlan@gmail.com>,
|
2019-10-17 20:48:46 -04:00
|
|
|
Victor Stinner <vstinner@python.org>,
|
2019-04-16 09:58:12 -04:00
|
|
|
Eric Snow <ericsnowcurrently@gmail.com>
|
2019-03-04 05:36:36 -05:00
|
|
|
Discussions-To: capi-sig@python.org
|
2020-08-15 20:20:05 -04:00
|
|
|
Status: Withdrawn
|
2012-12-27 09:41:16 -05:00
|
|
|
Type: Standards Track
|
|
|
|
Content-Type: text/x-rst
|
2019-04-16 09:58:12 -04:00
|
|
|
Requires: 587
|
2012-12-27 09:41:16 -05:00
|
|
|
Created: 28-Dec-2012
|
2022-03-09 11:04:44 -05:00
|
|
|
Post-History: 28-Dec-2012, 02-Jan-2013, 30-Mar-2019, 28-Jun-2020
|
2020-08-15 20:20:05 -04:00
|
|
|
|
2022-07-20 17:55:12 -04:00
|
|
|
.. highlight:: c
|
2020-08-15 20:20:05 -04:00
|
|
|
|
|
|
|
PEP Withdrawal
|
|
|
|
==============
|
|
|
|
|
|
|
|
From late 2012 to mid 2020, this PEP provided general background and specific
|
|
|
|
concrete proposals for making the CPython startup sequence easier to maintain
|
|
|
|
and the CPython runtime easier to embed as part of a larger application.
|
|
|
|
|
|
|
|
For most of that time, the changes were maintained either in a separate feature
|
|
|
|
branch, or else as underscore-prefixed private APIs in the main CPython repo.
|
|
|
|
|
2022-01-21 06:03:51 -05:00
|
|
|
In 2019, :pep:`587` migrated a subset of those API changes to the public CPython
|
2020-08-15 20:20:05 -04:00
|
|
|
API for Python 3.8+ (specifically, the PEP updated the interpreter runtime to
|
|
|
|
offer an explicitly multi-stage struct-based configuration interface).
|
|
|
|
|
|
|
|
In June 2020, in response to a query from the Steering Council, the PEP authors
|
|
|
|
decided that it made sense to withdraw the original PEP, as enough has changed
|
2022-01-21 06:03:51 -05:00
|
|
|
since :pep:`432` was first written that we think any further changes to the
|
2020-08-15 20:20:05 -04:00
|
|
|
startup sequence and embedding API would be best formulated as a new PEP (or
|
2022-01-21 06:03:51 -05:00
|
|
|
PEPs) that take into account not only the not-yet-implemented ideas from :pep:`432`
|
2020-08-15 20:20:05 -04:00
|
|
|
that weren't considered sufficiently well validated to make their way into
|
2022-01-21 06:03:51 -05:00
|
|
|
:pep:`587`, but also any feedback on the public :pep:`587` API, and any other lessons
|
2020-08-15 20:20:05 -04:00
|
|
|
that have been learned while adjusting the CPython implementation to be more
|
|
|
|
embedding and subinterpreter friendly.
|
|
|
|
|
|
|
|
In particular, PEPs proposing the following changes, and any further
|
|
|
|
infrastructure changes needed to enable them, would likely still be worth
|
|
|
|
exploring:
|
|
|
|
|
|
|
|
* shipping an alternate Python executable that ignores all user level
|
|
|
|
settings and runs in isolated mode by default, and would hence be more
|
|
|
|
suitable for execution of system level Python applications than the default
|
|
|
|
interpreter
|
|
|
|
* enhancing the zipapp module to support the creation of single-file executables
|
|
|
|
from pure Python scripts (and potentially even Python extension modules, given
|
|
|
|
the introduction of multi-phase extension module initialisation)
|
|
|
|
* migrating the complex sys.path initialisation logic from C to Python in order
|
|
|
|
to improve test suite coverage and the general maintainability of that code
|
2012-12-27 09:41:16 -05:00
|
|
|
|
|
|
|
|
|
|
|
Abstract
|
|
|
|
========
|
|
|
|
|
2016-12-31 02:07:04 -05:00
|
|
|
This PEP proposes a mechanism for restructuring the startup sequence for
|
2012-12-30 08:39:20 -05:00
|
|
|
CPython, making it easier to modify the initialization behaviour of the
|
2012-12-27 09:41:16 -05:00
|
|
|
reference interpreter executable, as well as making it easier to control
|
|
|
|
CPython's startup behaviour when creating an alternate executable or
|
|
|
|
embedding it as a Python execution engine inside a larger application.
|
|
|
|
|
2016-12-31 02:07:04 -05:00
|
|
|
When implementation of this proposal is completed, interpreter startup will
|
2019-03-02 21:17:22 -05:00
|
|
|
consist of three clearly distinct and independently configurable phases:
|
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
* Python core runtime preinitialization
|
2019-03-02 21:17:22 -05:00
|
|
|
|
|
|
|
* setting up memory management
|
|
|
|
* determining the encodings used for system interfaces (including settings
|
|
|
|
passed in for later configuration phase)
|
|
|
|
|
|
|
|
* Python core runtime initialization
|
|
|
|
|
|
|
|
* ensuring C API is ready for use
|
|
|
|
* ensuring builtin and frozen modules are accessible
|
2016-12-31 02:07:04 -05:00
|
|
|
|
|
|
|
* Main interpreter configuration
|
|
|
|
|
2019-03-02 21:17:22 -05:00
|
|
|
* ensuring external modules are accessible
|
|
|
|
* (Note: the name of this phase is quite likely to change)
|
|
|
|
|
2016-12-31 02:07:04 -05:00
|
|
|
Changes are also proposed that impact main module execution and subinterpreter
|
|
|
|
initialization.
|
|
|
|
|
2012-12-28 12:40:37 -05:00
|
|
|
Note: TBC = To Be Confirmed, TBD = To Be Determined. The appropriate
|
|
|
|
resolution for most of these should become clearer as the reference
|
|
|
|
implementation is developed.
|
|
|
|
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2012-12-30 08:39:20 -05:00
|
|
|
Proposal
|
|
|
|
========
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2015-06-30 07:43:19 -04:00
|
|
|
This PEP proposes that initialization of the CPython runtime be split into
|
2019-03-02 21:17:22 -05:00
|
|
|
three clearly distinct phases:
|
2012-12-30 08:39:20 -05:00
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
* core runtime preinitialization
|
2015-06-30 07:43:19 -04:00
|
|
|
* core runtime initialization
|
2016-12-31 02:07:04 -05:00
|
|
|
* main interpreter configuration
|
2012-12-30 08:39:20 -05:00
|
|
|
|
2019-03-02 21:17:22 -05:00
|
|
|
(Earlier versions proposed only two phases, but experience with attempting to
|
|
|
|
implement the PEP as an internal CPython refactoring showed that at least 3
|
|
|
|
phases are needed to get clear separation of concerns)
|
|
|
|
|
2015-06-30 07:43:19 -04:00
|
|
|
The proposed design also has significant implications for:
|
2015-04-13 19:26:10 -04:00
|
|
|
|
2015-06-30 07:43:19 -04:00
|
|
|
* main module execution
|
|
|
|
* subinterpreter initialization
|
2015-04-13 19:26:10 -04:00
|
|
|
|
2015-06-30 07:43:19 -04:00
|
|
|
In the new design, the interpreter will move through the following
|
|
|
|
well-defined phases during the initialization sequence:
|
2013-01-13 01:35:06 -05:00
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
* Uninitialized - haven't even started the pre-initialization phase yet
|
2015-06-30 07:43:19 -04:00
|
|
|
* Pre-Initialization - no interpreter available
|
2016-12-31 02:07:04 -05:00
|
|
|
* Runtime Initialized - main interpreter partially available,
|
2015-06-30 07:43:19 -04:00
|
|
|
subinterpreter creation not yet available
|
|
|
|
* Initialized - main interpreter fully available, subinterpreter creation
|
|
|
|
available
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2022-01-21 06:03:51 -05:00
|
|
|
:pep:`587` is a more detailed proposal that covers separating out the
|
2019-04-16 09:58:12 -04:00
|
|
|
Pre-Initialization phase from the last two phases, but doesn't allow embedding
|
|
|
|
applications to run arbitrary code while in the "Runtime Initialized" state
|
|
|
|
(instead, initializing the core runtime will also always fully initialize the
|
|
|
|
main interpreter, as that's the way the native CPython CLI still works in
|
|
|
|
Python 3.8).
|
|
|
|
|
2012-12-27 09:41:16 -05:00
|
|
|
As a concrete use case to help guide any design changes, and to solve a known
|
|
|
|
problem where the appropriate defaults for system utilities differ from those
|
2019-04-16 09:58:12 -04:00
|
|
|
for running user scripts, this PEP proposes the creation and
|
2016-09-20 22:27:00 -04:00
|
|
|
distribution of a separate system Python (``system-python``) executable
|
2015-06-30 07:43:19 -04:00
|
|
|
which, by default, operates in "isolated mode" (as selected by the CPython
|
2016-09-20 22:27:00 -04:00
|
|
|
``-I`` switch), as well as the creation of an example stub binary that just
|
|
|
|
runs an appended zip archive (permitting single-file pure Python executables)
|
|
|
|
rather than going through the normal CPython startup sequence.
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2012-12-28 12:40:37 -05:00
|
|
|
To keep the implementation complexity under control, this PEP does *not*
|
|
|
|
propose wholesale changes to the way the interpreter state is accessed at
|
2013-01-16 07:54:01 -05:00
|
|
|
runtime. Changing the order in which the existing initialization steps
|
2015-06-30 07:43:19 -04:00
|
|
|
occur in order to make the startup sequence easier to maintain is already a
|
|
|
|
substantial change, and attempting to make those other changes at the same time
|
|
|
|
will make the change significantly more invasive and much harder to review.
|
|
|
|
However, such proposals may be suitable topics for follow-on PEPs or patches
|
2019-04-16 09:58:12 -04:00
|
|
|
- one key benefit of this PEP and its related subproposals is decreasing the
|
|
|
|
coupling between the internal storage model and the configuration interface,
|
|
|
|
so such changes should be easier once this PEP has been implemented.
|
2012-12-28 12:40:37 -05:00
|
|
|
|
2012-12-27 09:41:16 -05:00
|
|
|
|
|
|
|
Background
|
|
|
|
==========
|
|
|
|
|
2012-12-30 08:39:20 -05:00
|
|
|
Over time, CPython's initialization sequence has become progressively more
|
2012-12-27 09:41:16 -05:00
|
|
|
complicated, offering more options, as well as performing more complex tasks
|
2022-07-20 17:55:12 -04:00
|
|
|
(such as configuring the Unicode settings for OS interfaces in Python 3 [10]_,
|
2015-04-13 19:26:10 -04:00
|
|
|
bootstrapping a pure Python implementation of the import system, and
|
|
|
|
implementing an isolated mode more suitable for system applications that run
|
2022-07-20 17:55:12 -04:00
|
|
|
with elevated privileges [6]_).
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2013-01-13 01:35:06 -05:00
|
|
|
Much of this complexity is formally accessible only through the ``Py_Main``
|
|
|
|
and ``Py_Initialize`` APIs, offering embedding applications little
|
|
|
|
opportunity for customisation. This creeping complexity also makes life
|
|
|
|
difficult for maintainers, as much of the configuration needs to take
|
|
|
|
place prior to the ``Py_Initialize`` call, meaning much of the Python C
|
|
|
|
API cannot be used safely.
|
2012-12-27 09:41:16 -05:00
|
|
|
|
|
|
|
A number of proposals are on the table for even *more* sophisticated
|
2015-04-13 19:26:10 -04:00
|
|
|
startup behaviour, such as better control over ``sys.path``
|
2015-06-30 07:43:19 -04:00
|
|
|
initialization (e.g. easily adding additional directories on the command line
|
2022-07-20 17:55:12 -04:00
|
|
|
in a cross-platform fashion [7]_, controlling the configuration of
|
|
|
|
``sys.path[0]`` [8]_), easier configuration of utilities like coverage
|
|
|
|
tracing when launching Python subprocesses [9]_).
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2015-04-13 19:26:10 -04:00
|
|
|
Rather than continuing to bolt such behaviour onto an already complicated
|
2016-12-31 02:07:04 -05:00
|
|
|
system indefinitely, this PEP proposes to start simplifying the status quo by
|
|
|
|
introducing a more structured startup sequence, with the aim of making these
|
|
|
|
further feature requests easier to implement.
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
Originally the entire proposal was maintained in this one PEP, but that proved
|
|
|
|
impractical, so as parts of the proposed design stabilised, they are now split
|
|
|
|
out into their own PEPs, allowing progress to be made, even while the details
|
|
|
|
of the overall design are still evolving.
|
|
|
|
|
2012-12-27 09:41:16 -05:00
|
|
|
|
|
|
|
Key Concerns
|
|
|
|
============
|
|
|
|
|
2015-12-27 06:44:47 -05:00
|
|
|
There are a few key concerns that any change to the startup sequence
|
2012-12-27 09:41:16 -05:00
|
|
|
needs to take into account.
|
|
|
|
|
|
|
|
|
|
|
|
Maintainability
|
|
|
|
---------------
|
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
The CPython startup sequence as of Python 3.6 was difficult to understand, and
|
|
|
|
even more difficult to modify. It was not clear what state the interpreter was
|
|
|
|
in while much of the initialization code executed, leading to behaviour such
|
2012-12-27 09:41:16 -05:00
|
|
|
as lists, dictionaries and Unicode values being created prior to the call
|
2022-07-20 17:55:12 -04:00
|
|
|
to ``Py_Initialize`` when the ``-X`` or ``-W`` options are used [1]_.
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2012-12-30 08:39:20 -05:00
|
|
|
By moving to an explicitly multi-phase startup sequence, developers should
|
2019-04-16 09:58:12 -04:00
|
|
|
only need to understand:
|
|
|
|
|
|
|
|
* which APIs and features are available prior to pre-configuration (essentially
|
|
|
|
none, except for the pre-configuration API itself)
|
|
|
|
* which APIs and features are available prior to core runtime configuration, and
|
|
|
|
will implicitly run the pre-configuration with default settings that match the
|
|
|
|
behaviour of Python 3.6 if the pre-configuration hasn't been run explicitly
|
|
|
|
* which APIs and features are only available after the main interpreter has been
|
|
|
|
fully configured (which will hopefully be a relatively small subset of the
|
|
|
|
full C API)
|
|
|
|
|
2022-01-21 06:03:51 -05:00
|
|
|
The first two aspects of that are covered by :pep:`587`, while the details of the
|
2019-04-16 09:58:12 -04:00
|
|
|
latter distinction are still being considered.
|
2012-12-27 09:41:16 -05:00
|
|
|
|
|
|
|
By basing the new design on a combination of C structures and Python
|
2013-01-02 06:25:24 -05:00
|
|
|
data types, it should also be easier to modify the system in the
|
2012-12-27 09:41:16 -05:00
|
|
|
future to add new configuration options.
|
|
|
|
|
|
|
|
|
2015-12-27 06:44:47 -05:00
|
|
|
Testability
|
|
|
|
-----------
|
|
|
|
|
|
|
|
One of the problems with the complexity of the CPython startup sequence is the
|
|
|
|
combinatorial explosion of possible interactions between different configuration
|
|
|
|
settings.
|
|
|
|
|
|
|
|
This concern impacts both the design of the new initialisation system, and
|
|
|
|
the proposed approach for getting there.
|
|
|
|
|
|
|
|
|
2012-12-27 09:41:16 -05:00
|
|
|
Performance
|
|
|
|
-----------
|
|
|
|
|
|
|
|
CPython is used heavily to run short scripts where the runtime is dominated
|
2012-12-30 08:39:20 -05:00
|
|
|
by the interpreter initialization time. Any changes to the startup sequence
|
2012-12-28 12:40:37 -05:00
|
|
|
should minimise their impact on the startup overhead.
|
|
|
|
|
|
|
|
Experience with the importlib migration suggests that the startup time is
|
|
|
|
dominated by IO operations. However, to monitor the impact of any changes,
|
|
|
|
a simple benchmark can be used to check how long it takes to start and then
|
2022-07-20 17:55:12 -04:00
|
|
|
tear down the interpreter:
|
|
|
|
|
|
|
|
.. code-block:: bash
|
2012-12-28 12:40:37 -05:00
|
|
|
|
2019-03-02 21:17:22 -05:00
|
|
|
python3 -m timeit -s "from subprocess import call" "call(['./python', '-Sc', 'pass'])"
|
2012-12-28 12:40:37 -05:00
|
|
|
|
2022-07-20 17:55:12 -04:00
|
|
|
Current numbers on my system for Python 3.7 (as built by the Fedora project):
|
|
|
|
|
2022-07-22 12:22:34 -04:00
|
|
|
.. code-block:: console
|
2012-12-29 03:55:47 -05:00
|
|
|
|
2019-03-02 21:17:22 -05:00
|
|
|
$ python3 -m timeit -s "from subprocess import call" "call(['python3', '-Sc', 'pass'])"
|
|
|
|
50 loops, best of 5: 6.48 msec per loop
|
|
|
|
|
|
|
|
(TODO: run this microbenchmark with perf rather than the stdlib timeit)
|
2012-12-29 03:55:47 -05:00
|
|
|
|
|
|
|
This PEP is not expected to have any significant effect on the startup time,
|
2012-12-30 08:39:20 -05:00
|
|
|
as it is aimed primarily at *reordering* the existing initialization
|
2012-12-29 03:55:47 -05:00
|
|
|
sequence, without making substantial changes to the individual steps.
|
|
|
|
|
|
|
|
However, if this simple check suggests that the proposed changes to the
|
2012-12-30 08:39:20 -05:00
|
|
|
initialization sequence may pose a performance problem, then a more
|
2012-12-29 03:55:47 -05:00
|
|
|
sophisticated microbenchmark will be developed to assist in investigation.
|
2012-12-28 12:40:37 -05:00
|
|
|
|
|
|
|
|
|
|
|
Required Configuration Settings
|
|
|
|
===============================
|
|
|
|
|
2022-01-21 06:03:51 -05:00
|
|
|
See :pep:`587` for a detailed listing of CPython interpreter configuration settings
|
2019-04-16 09:58:12 -04:00
|
|
|
and the various means available for setting them.
|
2012-12-27 09:41:16 -05:00
|
|
|
|
|
|
|
|
2015-12-27 06:44:47 -05:00
|
|
|
Implementation Strategy
|
|
|
|
=======================
|
|
|
|
|
|
|
|
An initial attempt was made at implementing an earlier version of this PEP for
|
2022-07-20 17:55:12 -04:00
|
|
|
Python 3.4 [2]_, with one of the significant problems encountered being merge
|
2015-12-27 06:44:47 -05:00
|
|
|
conflicts after the initial structural changes were put in place to start the
|
|
|
|
refactoring process. Unlike some other previous major changes, such as the
|
|
|
|
switch to an AST-based compiler in Python 2.5, or the switch to the importlib
|
|
|
|
implementation of the import system in Python 3.3, there is no clear way to
|
|
|
|
structure a draft implementation that won't be prone to the kinds of merge
|
|
|
|
conflicts that afflicted the original attempt.
|
|
|
|
|
2019-03-02 21:17:22 -05:00
|
|
|
Accordingly, the implementation strategy was revised to instead first implement
|
|
|
|
this refactoring as a private API for CPython 3.7, and then review the viability
|
|
|
|
of exposing the new functions and structures as public API elements in CPython
|
|
|
|
3.8.
|
|
|
|
|
|
|
|
After the initial merge, Victor Stinner then proceeded to actually migrate
|
2022-01-21 06:03:51 -05:00
|
|
|
settings to the new structure in order to successfully implement the :pep:`540`
|
2019-03-02 21:17:22 -05:00
|
|
|
UTF-8 mode changes (which required the ability to track all settings that had
|
|
|
|
previously been decoded with the locale encoding, and decode them again using
|
|
|
|
UTF-8 instead). Eric Snow also migrated a number of internal subsystems over as
|
|
|
|
part of making the subinterpreter feature more robust.
|
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
That work showed that the detailed design originally proposed in this PEP had a
|
|
|
|
range of practical issues, so Victor designed and implemented an improved
|
2022-01-21 06:03:51 -05:00
|
|
|
private API (inspired by an earlier iteration of this PEP), which :pep:`587`
|
2019-04-16 09:58:12 -04:00
|
|
|
proposes to promote to a public API in Python 3.8.
|
2015-12-27 06:44:47 -05:00
|
|
|
|
|
|
|
|
2012-12-30 08:39:20 -05:00
|
|
|
Design Details
|
|
|
|
==============
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2019-03-02 21:17:22 -05:00
|
|
|
.. note::
|
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
The API details here are still very much in flux. The header files that show
|
|
|
|
the current state of the private API are mainly:
|
2019-03-02 21:17:22 -05:00
|
|
|
|
|
|
|
* https://github.com/python/cpython/blob/master/Include/cpython/coreconfig.h
|
|
|
|
* https://github.com/python/cpython/blob/master/Include/cpython/pystate.h
|
|
|
|
* https://github.com/python/cpython/blob/master/Include/cpython/pylifecycle.h
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2022-01-21 06:03:51 -05:00
|
|
|
:pep:`587` covers the aspects of the API that are considered potentially stable
|
2019-04-16 09:58:12 -04:00
|
|
|
enough to make public. Where a proposed API is covered by that PEP,
|
|
|
|
"(see PEP 587)" is added to the text below.
|
|
|
|
|
2016-12-31 02:07:04 -05:00
|
|
|
The main theme of this proposal is to initialize the core language runtime
|
|
|
|
and create a partially initialized interpreter state for the main interpreter
|
|
|
|
*much* earlier in the startup process. This will allow most of the CPython API
|
|
|
|
to be used during the remainder of the initialization process, potentially
|
|
|
|
simplifying a number of operations that currently need to rely on basic C
|
|
|
|
functionality rather than being able to use the richer data structures provided
|
|
|
|
by the CPython C API.
|
2012-12-28 12:40:37 -05:00
|
|
|
|
2022-01-21 06:03:51 -05:00
|
|
|
:pep:`587` covers a subset of that task, which is splitting out the components that
|
2019-04-16 09:58:12 -04:00
|
|
|
even the existing "May be called before ``Py_Initialize``" interfaces need (like
|
|
|
|
memory allocators and operating system interface encoding details) into a
|
|
|
|
separate pre-configuration step.
|
|
|
|
|
2012-12-30 08:39:20 -05:00
|
|
|
In the following, the term "embedding application" also covers the standard
|
|
|
|
CPython command line application.
|
|
|
|
|
|
|
|
|
2013-01-02 06:25:24 -05:00
|
|
|
Interpreter Initialization Phases
|
|
|
|
---------------------------------
|
2012-12-30 08:39:20 -05:00
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
The following distinct interpreter initialisation phases are proposed:
|
|
|
|
|
|
|
|
* Uninitialized:
|
|
|
|
|
|
|
|
* Not really a phase, but the absence of a phase
|
|
|
|
* ``Py_IsInitializing()`` returns ``0``
|
|
|
|
* ``Py_IsRuntimeInitialized()`` returns ``0``
|
|
|
|
* ``Py_IsInitialized()`` returns ``0``
|
|
|
|
* The embedding application determines which memory allocator to use, and
|
|
|
|
which encoding to use to access operating system interfaces (or chooses
|
|
|
|
to delegate those decisions to the Python runtime)
|
|
|
|
* Application starts the initialization process by calling one of the
|
2022-01-21 06:03:51 -05:00
|
|
|
``Py_PreInitialize`` APIs (see :pep:`587`)
|
2012-12-30 08:39:20 -05:00
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
* Runtime Pre-Initialization:
|
2013-01-02 06:25:24 -05:00
|
|
|
|
2016-12-31 02:07:04 -05:00
|
|
|
* no interpreter is available
|
2019-04-16 09:58:12 -04:00
|
|
|
* ``Py_IsInitializing()`` returns ``1``
|
2016-12-31 02:07:04 -05:00
|
|
|
* ``Py_IsRuntimeInitialized()`` returns ``0``
|
2013-01-02 06:25:24 -05:00
|
|
|
* ``Py_IsInitialized()`` returns ``0``
|
2016-12-31 02:07:04 -05:00
|
|
|
* The embedding application determines the settings required to initialize
|
|
|
|
the core CPython runtime and create the main interpreter and moves to the
|
|
|
|
next phase by calling ``Py_InitializeRuntime``
|
2022-01-21 06:03:51 -05:00
|
|
|
* Note: as of :pep:`587`, the embedding application instead calls ``Py_Main()``,
|
2019-04-16 09:58:12 -04:00
|
|
|
``Py_UnixMain``, or one of the ``Py_Initialize`` APIs, and hence jumps
|
|
|
|
directly to the Initialized state.
|
2013-01-02 06:25:24 -05:00
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
* Main Interpreter Initialization:
|
2013-01-02 06:25:24 -05:00
|
|
|
|
2016-12-31 02:07:04 -05:00
|
|
|
* the builtin data types and other core runtime services are available
|
|
|
|
* the main interpreter is available, but only partially configured
|
2019-04-16 09:58:12 -04:00
|
|
|
* ``Py_IsInitializing()`` returns ``1``
|
2016-12-31 02:07:04 -05:00
|
|
|
* ``Py_IsRuntimeInitialized()`` returns ``1``
|
2013-01-02 06:25:24 -05:00
|
|
|
* ``Py_IsInitialized()`` returns ``0``
|
|
|
|
* The embedding application determines and applies the settings
|
|
|
|
required to complete the initialization process by calling
|
2019-04-16 09:58:12 -04:00
|
|
|
``Py_InitializeMainInterpreter``
|
2022-01-21 06:03:51 -05:00
|
|
|
* Note: as of :pep:`587`, this state is not reachable via any public API, it
|
2019-04-16 09:58:12 -04:00
|
|
|
only exists as an implicit internal state while one of the ``Py_Initialize``
|
|
|
|
functions is running
|
2013-01-02 06:25:24 -05:00
|
|
|
|
|
|
|
* Initialized:
|
|
|
|
|
|
|
|
* the main interpreter is available and fully operational, but
|
2013-01-13 01:35:06 -05:00
|
|
|
``__main__`` related metadata is incomplete
|
2019-04-16 09:58:12 -04:00
|
|
|
* ``Py_IsInitializing()`` returns ``0``
|
2016-12-31 02:07:04 -05:00
|
|
|
* ``Py_IsRuntimeInitialized()`` returns ``1``
|
2013-01-02 06:25:24 -05:00
|
|
|
* ``Py_IsInitialized()`` returns ``1``
|
2015-04-13 19:26:10 -04:00
|
|
|
|
2016-12-31 02:07:04 -05:00
|
|
|
|
2015-04-13 19:26:10 -04:00
|
|
|
Invocation of Phases
|
|
|
|
--------------------
|
2012-12-30 08:39:20 -05:00
|
|
|
|
2013-01-13 01:35:06 -05:00
|
|
|
All listed phases will be used by the standard CPython interpreter and the
|
2015-06-30 07:43:19 -04:00
|
|
|
proposed System Python interpreter.
|
2012-12-30 08:39:20 -05:00
|
|
|
|
2013-01-02 06:25:24 -05:00
|
|
|
An embedding application may still continue to leave initialization almost
|
2012-12-30 10:49:02 -05:00
|
|
|
entirely under CPython's control by using the existing ``Py_Initialize``
|
2019-04-16 09:58:12 -04:00
|
|
|
or ``Py_Main()`` APIs - backwards compatibility will be preserved.
|
|
|
|
|
|
|
|
Alternatively, if an embedding application wants greater control
|
2012-12-30 10:49:02 -05:00
|
|
|
over CPython's initial state, it will be able to use the new, finer
|
|
|
|
grained API, which allows the embedding application greater control
|
2019-04-16 09:58:12 -04:00
|
|
|
over the initialization process.
|
2012-12-30 10:49:02 -05:00
|
|
|
|
2022-01-21 06:03:51 -05:00
|
|
|
:pep:`587` covers an initial iteration of that API, separating out the
|
2019-04-16 09:58:12 -04:00
|
|
|
pre-initialization phase without attempting to separate core runtime
|
|
|
|
initialization from main interpreter initialization.
|
|
|
|
|
|
|
|
|
|
|
|
Uninitialized State
|
|
|
|
-------------------
|
|
|
|
|
2019-07-03 14:20:45 -04:00
|
|
|
The uninitialized state is where an embedding application determines the settings
|
2019-04-16 09:58:12 -04:00
|
|
|
which are required in order to be able to correctly pass configurations settings
|
|
|
|
to the embedded Python runtime.
|
|
|
|
|
|
|
|
This covers telling Python which memory allocator to use, as well as which text
|
|
|
|
encoding to use when processing provided settings.
|
|
|
|
|
2022-01-21 06:03:51 -05:00
|
|
|
:pep:`587` defines the settings needed to exit this state in its ``PyPreConfig``
|
2019-04-16 09:58:12 -04:00
|
|
|
struct.
|
|
|
|
|
|
|
|
A new query API will allow code to determine if the interpreter hasn't even
|
|
|
|
started the initialization process::
|
|
|
|
|
|
|
|
int Py_IsInitializing();
|
|
|
|
|
2019-07-03 14:20:45 -04:00
|
|
|
The query for a completely uninitialized environment would then be
|
2019-04-16 09:58:12 -04:00
|
|
|
``!(Py_Initialized() || Py_Initializing())``.
|
|
|
|
|
|
|
|
|
|
|
|
Runtime Pre-Initialization Phase
|
|
|
|
--------------------------------
|
|
|
|
|
2022-01-21 06:03:51 -05:00
|
|
|
.. note:: In :pep:`587`, the settings for this phase are not yet separated out,
|
2019-04-16 09:58:12 -04:00
|
|
|
and are instead only available through the combined ``PyConfig`` struct
|
2012-12-28 12:40:37 -05:00
|
|
|
|
2012-12-30 08:39:20 -05:00
|
|
|
The pre-initialization phase is where an embedding application determines
|
2016-12-31 02:07:04 -05:00
|
|
|
the settings which are absolutely required before the CPython runtime can be
|
2015-04-13 19:26:10 -04:00
|
|
|
initialized at all. Currently, the primary configuration settings in this
|
2012-12-30 08:39:20 -05:00
|
|
|
category are those related to the randomised hash algorithm - the hash
|
|
|
|
algorithms must be consistent for the lifetime of the process, and so they
|
|
|
|
must be in place before the core interpreter is created.
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
The essential settings needed are a flag indicating whether or not to use a
|
2012-12-30 08:39:20 -05:00
|
|
|
specific seed value for the randomised hashes, and if so, the specific value
|
|
|
|
for the seed (a seed value of zero disables randomised hashing). In addition,
|
2013-01-02 06:25:24 -05:00
|
|
|
due to the possible use of ``PYTHONHASHSEED`` in configuring the hash
|
|
|
|
randomisation, the question of whether or not to consider environment
|
2013-01-15 07:28:45 -05:00
|
|
|
variables must also be addressed early. Finally, to support the CPython
|
|
|
|
build process, an option is offered to completely disable the import
|
|
|
|
system.
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
The proposed APIs for this step in the startup sequence are::
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
PyInitError Py_InitializeRuntime(
|
|
|
|
const PyRuntimeConfig *config
|
|
|
|
);
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
PyInitError Py_InitializeRuntimeFromArgs(
|
|
|
|
const PyRuntimeConfig *config, int argc, char **argv
|
|
|
|
);
|
|
|
|
|
|
|
|
PyInitError Py_InitializeRuntimeFromWideArgs(
|
|
|
|
const PyRuntimeConfig *config, int argc, wchar_t **argv
|
|
|
|
);
|
|
|
|
|
|
|
|
If ``Py_IsInitializing()`` is false, the ``Py_InitializeRuntime`` functions will
|
|
|
|
implicitly call the corresponding ``Py_PreInitialize`` function. The
|
|
|
|
``use_environment`` setting will be passed down, while other settings will be
|
2022-01-21 06:03:51 -05:00
|
|
|
processed according to their defaults, as described in :pep:`587`.
|
2019-04-16 09:58:12 -04:00
|
|
|
|
2022-01-21 06:03:51 -05:00
|
|
|
The ``PyInitError`` return type is defined in :pep:`587`, and allows an embedding
|
2019-04-16 09:58:12 -04:00
|
|
|
application to gracefully handle Python runtime initialization failures,
|
|
|
|
rather than having the entire process abruptly terminated by ``Py_FatalError``.
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2016-12-31 02:07:04 -05:00
|
|
|
The new ``PyRuntimeConfig`` struct holds the settings required for preliminary
|
2015-06-30 07:43:19 -04:00
|
|
|
configuration of the core runtime and creation of the main interpreter::
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2016-12-31 02:07:04 -05:00
|
|
|
/* Note: if changing anything in PyRuntimeConfig, also update
|
|
|
|
* PyRuntimeConfig_INIT */
|
2012-12-27 09:41:16 -05:00
|
|
|
typedef struct {
|
2019-04-16 09:58:12 -04:00
|
|
|
bool use_environment; /* as in PyPreConfig, PyConfig from PEP 587 */
|
|
|
|
int use_hash_seed; /* PYTHONHASHSEED, as in PyConfig from PEP 587 */
|
|
|
|
unsigned long hash_seed; /* PYTHONHASHSEED, as in PyConfig from PEP 587 */
|
|
|
|
bool _install_importlib; /* Needed by freeze_importlib */
|
2016-12-31 02:07:04 -05:00
|
|
|
} PyRuntimeConfig;
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2016-12-31 02:07:04 -05:00
|
|
|
/* Rely on the "designated initializer" feature of C99 */
|
|
|
|
#define PyRuntimeConfig_INIT {.use_hash_seed=-1}
|
2012-12-30 10:32:51 -05:00
|
|
|
|
2012-12-30 08:39:20 -05:00
|
|
|
The core configuration settings pointer may be ``NULL``, in which case the
|
2016-12-31 02:07:04 -05:00
|
|
|
default values are as specified in ``PyRuntimeConfig_INIT``.
|
2012-12-30 08:39:20 -05:00
|
|
|
|
2016-12-31 02:07:04 -05:00
|
|
|
The ``PyRuntimeConfig_INIT`` macro is designed to allow easy initialization
|
2012-12-30 10:32:51 -05:00
|
|
|
of a struct instance with sensible defaults::
|
|
|
|
|
2016-12-31 02:07:04 -05:00
|
|
|
PyRuntimeConfig runtime_config = PyRuntimeConfig_INIT;
|
2012-12-30 10:32:51 -05:00
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
``use_environment`` controls the processing of all Python related
|
|
|
|
environment variables. If the flag is true, then ``PYTHONHASHSEED`` is
|
2012-12-30 08:39:20 -05:00
|
|
|
processed normally. Otherwise, all Python-specific environment variables
|
|
|
|
are considered undefined (exceptions may be made for some OS specific
|
|
|
|
environment variables, such as those used on Mac OS X to communicate
|
|
|
|
between the App bundle and the main Python binary).
|
|
|
|
|
|
|
|
``use_hash_seed`` controls the configuration of the randomised hash
|
|
|
|
algorithm. If it is zero, then randomised hashes with a random seed will
|
2016-07-11 11:14:08 -04:00
|
|
|
be used. It is positive, then the value in ``hash_seed`` will be used
|
2012-12-30 08:39:20 -05:00
|
|
|
to seed the random number generator. If the ``hash_seed`` is zero in this
|
|
|
|
case, then the randomised hashing is disabled completely.
|
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
If ``use_hash_seed`` is negative (and ``use_environment`` is true),
|
2015-04-13 19:26:10 -04:00
|
|
|
then CPython will inspect the ``PYTHONHASHSEED`` environment variable. If the
|
|
|
|
environment variable is not set, is set to the empty string, or to the value
|
|
|
|
``"random"``, then randomised hashes with a random seed will be used. If the
|
|
|
|
environment variable is set to the string ``"0"`` the randomised hashing will
|
|
|
|
be disabled. Otherwise, the hash seed is expected to be a string
|
|
|
|
representation of an integer in the range ``[0; 4294967295]``.
|
2012-12-30 08:39:20 -05:00
|
|
|
|
|
|
|
To make it easier for embedding applications to use the ``PYTHONHASHSEED``
|
|
|
|
processing with a different data source, the following helper function
|
|
|
|
will be added to the C API::
|
|
|
|
|
|
|
|
int Py_ReadHashSeed(char *seed_text,
|
|
|
|
int *use_hash_seed,
|
|
|
|
unsigned long *hash_seed);
|
|
|
|
|
|
|
|
This function accepts a seed string in ``seed_text`` and converts it to
|
|
|
|
the appropriate flag and seed values. If ``seed_text`` is ``NULL``,
|
|
|
|
the empty string or the value ``"random"``, both ``use_hash_seed`` and
|
|
|
|
``hash_seed`` will be set to zero. Otherwise, ``use_hash_seed`` will be set to
|
|
|
|
``1`` and the seed text will be interpreted as an integer and reported as
|
|
|
|
``hash_seed``. On success the function will return zero. A non-zero return
|
|
|
|
value indicates an error (most likely in the conversion to an integer).
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
The ``_install_importlib`` setting is used as part of the CPython build
|
2013-01-12 09:48:28 -05:00
|
|
|
process to create an interpreter with no import capability at all. It is
|
|
|
|
considered private to the CPython development team (hence the leading
|
2016-12-31 02:07:04 -05:00
|
|
|
underscore), as the only currently supported use case is to permit compiler
|
|
|
|
changes that invalidate the previously frozen bytecode for
|
|
|
|
``importlib._bootstrap`` without breaking the build process.
|
2013-01-12 09:48:28 -05:00
|
|
|
|
2012-12-28 12:40:37 -05:00
|
|
|
The aim is to keep this initial level of configuration as small as possible
|
|
|
|
in order to keep the bootstrapping environment consistent across
|
|
|
|
different embedding applications. If we can create a valid interpreter state
|
2019-04-16 09:58:12 -04:00
|
|
|
without the setting, then the setting should appear solely in the comprehensive
|
|
|
|
``PyConfig`` struct rather than in the core runtime configuration.
|
2012-12-28 12:40:37 -05:00
|
|
|
|
2012-12-27 09:41:16 -05:00
|
|
|
A new query API will allow code to determine if the interpreter is in the
|
2016-12-31 02:07:04 -05:00
|
|
|
bootstrapping state between the core runtime initialization and the creation of
|
|
|
|
the main interpreter state and the completion of the bulk of the main
|
|
|
|
interpreter initialization process::
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2016-12-31 02:07:04 -05:00
|
|
|
int Py_IsRuntimeInitialized();
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2016-12-31 02:07:04 -05:00
|
|
|
Attempting to call ``Py_InitializeRuntime()`` again when
|
2019-04-16 09:58:12 -04:00
|
|
|
``Py_IsRuntimeInitialized()`` is already true is reported as a user
|
|
|
|
configuration error. (TBC, as existing public initialisation APIs support being
|
|
|
|
called multiple times without error, and simply ignore changes to any
|
|
|
|
write-once settings. It may make sense to keep that behaviour rather than trying
|
|
|
|
to make the new API stricter than the old one)
|
2012-12-28 12:40:37 -05:00
|
|
|
|
2015-06-30 07:43:19 -04:00
|
|
|
As frozen bytecode may now be legitimately run in an interpreter which is not
|
|
|
|
yet fully initialized, ``sys.flags`` will gain a new ``initialized`` flag.
|
|
|
|
|
2016-12-31 02:07:04 -05:00
|
|
|
With the core runtime initialised, the main interpreter and most of the CPython
|
|
|
|
C API should be fully functional except that:
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2012-12-28 12:40:37 -05:00
|
|
|
* compilation is not allowed (as the parser and compiler are not yet
|
|
|
|
configured properly)
|
2013-01-02 06:25:24 -05:00
|
|
|
* creation of subinterpreters is not allowed
|
|
|
|
* creation of additional thread states is not allowed
|
2012-12-27 09:41:16 -05:00
|
|
|
* The following attributes in the ``sys`` module are all either missing or
|
|
|
|
``None``:
|
|
|
|
* ``sys.path``
|
|
|
|
* ``sys.argv``
|
|
|
|
* ``sys.executable``
|
|
|
|
* ``sys.base_exec_prefix``
|
|
|
|
* ``sys.base_prefix``
|
|
|
|
* ``sys.exec_prefix``
|
|
|
|
* ``sys.prefix``
|
|
|
|
* ``sys.warnoptions``
|
|
|
|
* ``sys.dont_write_bytecode``
|
|
|
|
* ``sys.stdin``
|
|
|
|
* ``sys.stdout``
|
|
|
|
* The filesystem encoding is not yet defined
|
|
|
|
* The IO encoding is not yet defined
|
|
|
|
* CPython signal handlers are not yet installed
|
2015-06-30 07:43:19 -04:00
|
|
|
* Only builtin and frozen modules may be imported (due to above limitations)
|
2012-12-27 09:41:16 -05:00
|
|
|
* ``sys.stderr`` is set to a temporary IO object using unbuffered binary
|
|
|
|
mode
|
2015-12-27 06:44:47 -05:00
|
|
|
* The ``sys.flags`` attribute exists, but the individual flags may not yet
|
2015-06-30 07:43:19 -04:00
|
|
|
have their final values.
|
|
|
|
* The ``sys.flags.initialized`` attribute is set to ``0``
|
2012-12-30 08:39:20 -05:00
|
|
|
* The ``warnings`` module is not yet initialized
|
2012-12-27 09:41:16 -05:00
|
|
|
* The ``__main__`` module does not yet exist
|
|
|
|
|
|
|
|
<TBD: identify any other notable missing functionality>
|
|
|
|
|
|
|
|
The main things made available by this step will be the core Python
|
2015-06-30 07:43:19 -04:00
|
|
|
data types, in particular dictionaries, lists and strings. This allows them
|
2012-12-27 09:41:16 -05:00
|
|
|
to be used safely for all of the remaining configuration steps (unlike the
|
|
|
|
status quo).
|
|
|
|
|
|
|
|
In addition, the current thread will possess a valid Python thread state,
|
2016-12-31 02:07:04 -05:00
|
|
|
allowing any further configuration data to be stored on the main interpreter
|
2015-04-13 19:26:10 -04:00
|
|
|
object rather than in C process globals.
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2016-12-31 02:07:04 -05:00
|
|
|
Any call to ``Py_InitializeRuntime()`` must have a matching call to
|
2015-06-30 07:43:19 -04:00
|
|
|
``Py_Finalize()``. It is acceptable to skip calling
|
2019-04-16 09:58:12 -04:00
|
|
|
``Py_InitializeMainInterpreter()`` in between (e.g. if attempting to build the
|
2015-12-27 06:44:47 -05:00
|
|
|
main interpreter configuration settings fails).
|
2012-12-27 09:41:16 -05:00
|
|
|
|
|
|
|
|
|
|
|
Determining the remaining configuration settings
|
|
|
|
------------------------------------------------
|
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
The next step in the initialization sequence is to determine the remaining
|
2012-12-27 09:41:16 -05:00
|
|
|
settings needed to complete the process. No changes are made to the
|
2019-04-16 09:58:12 -04:00
|
|
|
interpreter state at this point. The core APIs for this step are::
|
|
|
|
|
|
|
|
int Py_BuildPythonConfig(
|
|
|
|
PyConfigAsObjects *py_config, const PyConfig *c_config
|
|
|
|
);
|
|
|
|
|
|
|
|
int Py_BuildPythonConfigFromArgs(
|
|
|
|
PyConfigAsObjects *py_config, const PyConfig *c_config, int argc, char **argv
|
|
|
|
);
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
int Py_BuildPythonConfigFromWideArgs(
|
|
|
|
PyConfigAsObjects *py_config, const PyConfig *c_config, int argc, wchar_t **argv
|
|
|
|
);
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
The ``py_config`` argument should be a pointer to a PyConfigAsObjects struct
|
|
|
|
(which may be a temporary one stored on the C stack). For any already configured
|
|
|
|
value (i.e. any non-NULL pointer), CPython will sanity check the supplied value,
|
2016-12-31 02:07:04 -05:00
|
|
|
but otherwise accept it as correct.
|
2013-01-06 02:22:45 -05:00
|
|
|
|
|
|
|
A struct is used rather than a Python dictionary as the struct is easier
|
|
|
|
to work with from C, the list of supported fields is fixed for a given
|
2015-04-13 19:26:10 -04:00
|
|
|
CPython version and only a read-only view needs to be exposed to Python
|
2013-01-06 02:22:45 -05:00
|
|
|
code (which is relatively straightforward, thanks to the infrastructure
|
|
|
|
already put in place to expose ``sys.implementation``).
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
Unlike ``Py_InitializeRuntime``, this call will raise a Python exception and
|
|
|
|
report an error return rather than returning a Python initialization specific
|
|
|
|
C struct if a problem is found with the config data.
|
2012-12-27 09:41:16 -05:00
|
|
|
|
|
|
|
Any supported configuration setting which is not already set will be
|
2013-01-06 02:22:45 -05:00
|
|
|
populated appropriately in the supplied configuration struct. The default
|
2015-04-13 19:26:10 -04:00
|
|
|
configuration can be overridden entirely by setting the value *before*
|
2019-04-16 09:58:12 -04:00
|
|
|
calling ``Py_BuildPythonConfig``. The provided value will then also be
|
2015-06-30 07:43:19 -04:00
|
|
|
used in calculating any other settings derived from that value.
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2013-01-02 06:25:24 -05:00
|
|
|
Alternatively, settings may be overridden *after* the
|
2019-04-16 09:58:12 -04:00
|
|
|
``Py_BuildPythonConfig`` call (this can be useful if an embedding
|
2013-01-02 06:25:24 -05:00
|
|
|
application wants to adjust a setting rather than replace it completely,
|
|
|
|
such as removing ``sys.path[0]``).
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
The ``c_config`` argument is an optional pointer to a ``PyConfig`` structure,
|
2022-01-21 06:03:51 -05:00
|
|
|
as defined in :pep:`587`. If provided, it is used in preference to reading settings
|
2019-04-16 09:58:12 -04:00
|
|
|
directly from the environment or process global state.
|
|
|
|
|
2013-01-06 02:22:45 -05:00
|
|
|
Merely reading the configuration has no effect on the interpreter state: it
|
|
|
|
only modifies the passed in configuration struct. The settings are not
|
2019-04-16 09:58:12 -04:00
|
|
|
applied to the running interpreter until the ``Py_InitializeMainInterpreter``
|
2015-06-30 07:43:19 -04:00
|
|
|
call (see below).
|
2013-01-06 02:22:45 -05:00
|
|
|
|
2012-12-27 09:41:16 -05:00
|
|
|
|
|
|
|
Supported configuration settings
|
|
|
|
--------------------------------
|
|
|
|
|
2015-06-30 07:43:19 -04:00
|
|
|
The interpreter configuration is split into two parts: settings which are
|
|
|
|
either relevant only to the main interpreter or must be identical across the
|
|
|
|
main interpreter and all subinterpreters, and settings which may vary across
|
|
|
|
subinterpreters.
|
|
|
|
|
|
|
|
NOTE: For initial implementation purposes, only the flag indicating whether
|
|
|
|
or not the interpreter is the main interpreter will be configured on a per
|
|
|
|
interpreter basis. Other fields will be reviewed for whether or not they can
|
|
|
|
feasibly be made interpreter specific over the course of the implementation.
|
|
|
|
|
2022-01-21 06:03:51 -05:00
|
|
|
.. note:: The list of config fields below is currently out of sync with :pep:`587`.
|
|
|
|
Where they differ, :pep:`587` takes precedence.
|
2019-04-16 09:58:12 -04:00
|
|
|
|
2022-01-21 06:03:51 -05:00
|
|
|
The ``PyConfigAsObjects`` struct mirrors the ``PyConfig`` struct from :pep:`587`,
|
2019-04-16 09:58:12 -04:00
|
|
|
but uses full Python objects to store values, rather than C level data types.
|
|
|
|
It adds ``raw_argv`` and ``argv`` list fields, so later initialisation steps
|
|
|
|
don't need to accept those separately.
|
|
|
|
|
|
|
|
Fields are always pointers to Python data types, with unset values indicated by
|
|
|
|
``NULL``::
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2013-01-02 06:25:24 -05:00
|
|
|
typedef struct {
|
|
|
|
/* Argument processing */
|
2013-01-06 02:22:45 -05:00
|
|
|
PyListObject *raw_argv;
|
|
|
|
PyListObject *argv;
|
|
|
|
PyListObject *warnoptions; /* -W switch, PYTHONWARNINGS */
|
|
|
|
PyDictObject *xoptions; /* -X switch */
|
2013-01-02 06:25:24 -05:00
|
|
|
|
|
|
|
/* Filesystem locations */
|
2013-01-06 02:22:45 -05:00
|
|
|
PyUnicodeObject *program_name;
|
|
|
|
PyUnicodeObject *executable;
|
|
|
|
PyUnicodeObject *prefix; /* PYTHONHOME */
|
|
|
|
PyUnicodeObject *exec_prefix; /* PYTHONHOME */
|
|
|
|
PyUnicodeObject *base_prefix; /* pyvenv.cfg */
|
|
|
|
PyUnicodeObject *base_exec_prefix; /* pyvenv.cfg */
|
2013-01-02 06:25:24 -05:00
|
|
|
|
|
|
|
/* Site module */
|
2016-09-20 22:27:00 -04:00
|
|
|
PyBoolObject *enable_site_config; /* -S switch (inverted) */
|
|
|
|
PyBoolObject *no_user_site; /* -s switch, PYTHONNOUSERSITE */
|
2013-01-02 06:25:24 -05:00
|
|
|
|
|
|
|
/* Import configuration */
|
2016-09-20 22:27:00 -04:00
|
|
|
PyBoolObject *dont_write_bytecode; /* -B switch, PYTHONDONTWRITEBYTECODE */
|
|
|
|
PyBoolObject *ignore_module_case; /* PYTHONCASEOK */
|
|
|
|
PyListObject *import_path; /* PYTHONPATH (etc) */
|
2013-01-02 06:25:24 -05:00
|
|
|
|
|
|
|
/* Standard streams */
|
2016-09-20 22:27:00 -04:00
|
|
|
PyBoolObject *use_unbuffered_io; /* -u switch, PYTHONUNBUFFEREDIO */
|
|
|
|
PyUnicodeObject *stdin_encoding; /* PYTHONIOENCODING */
|
|
|
|
PyUnicodeObject *stdin_errors; /* PYTHONIOENCODING */
|
|
|
|
PyUnicodeObject *stdout_encoding; /* PYTHONIOENCODING */
|
|
|
|
PyUnicodeObject *stdout_errors; /* PYTHONIOENCODING */
|
|
|
|
PyUnicodeObject *stderr_encoding; /* PYTHONIOENCODING */
|
|
|
|
PyUnicodeObject *stderr_errors; /* PYTHONIOENCODING */
|
2013-01-02 06:25:24 -05:00
|
|
|
|
|
|
|
/* Filesystem access */
|
2013-01-06 02:22:45 -05:00
|
|
|
PyUnicodeObject *fs_encoding;
|
2013-01-02 06:25:24 -05:00
|
|
|
|
|
|
|
/* Debugging output */
|
2016-09-20 22:27:00 -04:00
|
|
|
PyBoolObject *debug_parser; /* -d switch, PYTHONDEBUG */
|
|
|
|
PyLongObject *verbosity; /* -v switch */
|
2013-01-02 06:25:24 -05:00
|
|
|
|
|
|
|
/* Code generation */
|
2016-09-20 22:27:00 -04:00
|
|
|
PyLongObject *bytes_warnings; /* -b switch */
|
|
|
|
PyLongObject *optimize; /* -O switch */
|
2013-01-02 06:25:24 -05:00
|
|
|
|
|
|
|
/* Signal handling */
|
2016-09-20 22:27:00 -04:00
|
|
|
PyBoolObject *install_signal_handlers;
|
2013-01-13 01:35:06 -05:00
|
|
|
|
|
|
|
/* Implicit execution */
|
|
|
|
PyUnicodeObject *startup_file; /* PYTHONSTARTUP */
|
|
|
|
|
|
|
|
/* Main module
|
|
|
|
*
|
|
|
|
* If prepare_main is set, at most one of the main_* settings should
|
2015-12-27 06:44:47 -05:00
|
|
|
* be set before calling PyRun_PrepareMain (Py_ReadMainInterpreterConfig
|
|
|
|
* will set one of them based on the command line arguments if
|
|
|
|
* prepare_main is non-zero when that API is called).
|
2016-09-20 22:27:00 -04:00
|
|
|
PyBoolObject *prepare_main;
|
2013-01-13 01:35:06 -05:00
|
|
|
PyUnicodeObject *main_source; /* -c switch */
|
|
|
|
PyUnicodeObject *main_path; /* filesystem path */
|
|
|
|
PyUnicodeObject *main_module; /* -m switch */
|
|
|
|
PyCodeObject *main_code; /* Run directly from a code object */
|
|
|
|
PyObject *main_stream; /* Run from stream */
|
2016-09-20 22:27:00 -04:00
|
|
|
PyBoolObject *run_implicit_code; /* Run implicit code during prep */
|
2013-01-13 01:35:06 -05:00
|
|
|
|
|
|
|
/* Interactive main
|
|
|
|
*
|
|
|
|
* Note: Settings related to interactive mode are very much in flux.
|
|
|
|
*/
|
|
|
|
PyObject *prompt_stream; /* Output interactive prompt */
|
2016-09-20 22:27:00 -04:00
|
|
|
PyBoolObject *show_banner; /* -q switch (inverted) */
|
|
|
|
PyBoolObject *inspect_main; /* -i switch, PYTHONINSPECT */
|
2013-01-13 01:35:06 -05:00
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
} PyConfigAsObjects;
|
2013-01-02 06:25:24 -05:00
|
|
|
|
2015-06-30 07:43:19 -04:00
|
|
|
The ``PyInterpreterConfig`` struct holds the settings that may vary between
|
|
|
|
the main interpreter and subinterpreters. For the main interpreter, these
|
2019-04-16 09:58:12 -04:00
|
|
|
settings are automatically populated by ``Py_InitializeMainInterpreter()``.
|
2015-06-30 07:43:19 -04:00
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
typedef struct {
|
2016-09-20 22:27:00 -04:00
|
|
|
PyBoolObject *is_main_interpreter; /* Easily check for subinterpreters */
|
2015-06-30 07:43:19 -04:00
|
|
|
} PyInterpreterConfig;
|
|
|
|
|
2016-12-31 02:07:04 -05:00
|
|
|
As these structs consist solely of object pointers, no explicit initializer
|
|
|
|
definitions are needed - C99's default initialization of struct memory to zero
|
|
|
|
is sufficient.
|
|
|
|
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
Completing the main interpreter initialization
|
|
|
|
----------------------------------------------
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2012-12-30 08:39:20 -05:00
|
|
|
The final step in the initialization process is to actually put the
|
2015-06-30 07:43:19 -04:00
|
|
|
configuration settings into effect and finish bootstrapping the main
|
|
|
|
interpreter up to full operation::
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
int Py_InitializeMainInterpreter(const PyConfigAsObjects *config);
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
Like ``Py_BuildPythonConfig``, this call will raise an exception and
|
2015-06-30 07:43:19 -04:00
|
|
|
report an error return rather than exhibiting fatal errors if a problem is
|
2019-04-16 09:58:12 -04:00
|
|
|
found with the config data. (TBC, as existing public initialisation APIs support
|
|
|
|
being called multiple times without error, and simply ignore changes to any
|
|
|
|
write-once settings. It may make sense to keep that behaviour rather than trying
|
|
|
|
to make the new API stricter than the old one)
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2013-01-02 06:25:24 -05:00
|
|
|
All configuration settings are required - the configuration struct
|
2019-04-16 09:58:12 -04:00
|
|
|
should always be passed through ``Py_BuildPythonConfig`` to ensure it
|
2012-12-28 12:40:37 -05:00
|
|
|
is fully populated.
|
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
After a successful call ``Py_IsInitialized()`` will become true and
|
|
|
|
``Py_IsInitializing()`` will become false. The caveats described above for the
|
|
|
|
interpreter during the phase where only the core runtime is initialized will
|
|
|
|
no longer hold.
|
2012-12-30 08:39:20 -05:00
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
Attempting to call ``Py_InitializeMainInterpreter()`` again when
|
2015-06-30 07:43:19 -04:00
|
|
|
``Py_IsInitialized()`` is true is an error.
|
2013-01-06 02:22:45 -05:00
|
|
|
|
2012-12-30 08:39:20 -05:00
|
|
|
However, some metadata related to the ``__main__`` module may still be
|
|
|
|
incomplete:
|
|
|
|
|
|
|
|
* ``sys.argv[0]`` may not yet have its final value
|
2012-12-30 10:12:03 -05:00
|
|
|
|
2012-12-30 08:39:20 -05:00
|
|
|
* it will be ``-m`` when executing a module or package with CPython
|
|
|
|
* it will be the same as ``sys.path[0]`` rather than the location of
|
|
|
|
the ``__main__`` module when executing a valid ``sys.path`` entry
|
|
|
|
(typically a zipfile or directory)
|
2013-01-13 01:35:06 -05:00
|
|
|
* otherwise, it will be accurate:
|
|
|
|
|
2016-05-03 04:18:02 -04:00
|
|
|
* the script name if running an ordinary script
|
|
|
|
* ``-c`` if executing a supplied string
|
|
|
|
* ``-`` or the empty string if running from stdin
|
2012-12-30 10:12:03 -05:00
|
|
|
|
2012-12-30 08:39:20 -05:00
|
|
|
* the metadata in the ``__main__`` module will still indicate it is a
|
|
|
|
builtin module
|
|
|
|
|
2013-01-06 02:22:45 -05:00
|
|
|
This function will normally implicitly import site as its final operation
|
2016-12-31 02:07:04 -05:00
|
|
|
(after ``Py_IsInitialized()`` is already set). Setting the
|
|
|
|
"enable_site_config" flag to ``Py_False`` in the configuration settings will
|
|
|
|
disable this behaviour, as well as eliminating any side effects on global
|
|
|
|
state if ``import site`` is later explicitly executed in the process.
|
2013-01-06 02:22:45 -05:00
|
|
|
|
2012-12-30 08:39:20 -05:00
|
|
|
|
2013-01-13 01:35:06 -05:00
|
|
|
Preparing the main module
|
|
|
|
-------------------------
|
|
|
|
|
2022-01-21 06:03:51 -05:00
|
|
|
.. note:: In :pep:`587`, ``PyRun_PrepareMain`` and ``PyRun_ExecMain`` are not
|
2019-04-16 09:58:12 -04:00
|
|
|
exposed separately, and are instead accessed through a ``Py_RunMain`` API
|
|
|
|
that both prepares and executes main, and then finalizes the Python
|
|
|
|
interpreter.
|
|
|
|
|
2013-01-13 01:35:06 -05:00
|
|
|
This subphase completes the population of the ``__main__`` module
|
|
|
|
related metadata, without actually starting execution of the ``__main__``
|
|
|
|
module code.
|
|
|
|
|
|
|
|
It is handled by calling the following API::
|
|
|
|
|
|
|
|
int PyRun_PrepareMain();
|
|
|
|
|
2015-06-30 07:43:19 -04:00
|
|
|
This operation is only permitted for the main interpreter, and will raise
|
|
|
|
``RuntimeError`` when invoked from a thread where the current thread state
|
|
|
|
belongs to a subinterpreter.
|
|
|
|
|
2013-01-13 01:35:06 -05:00
|
|
|
The actual processing is driven by the main related settings stored in
|
|
|
|
the interpreter state as part of the configuration struct.
|
|
|
|
|
|
|
|
If ``prepare_main`` is zero, this call does nothing.
|
|
|
|
|
|
|
|
If all of ``main_source``, ``main_path``, ``main_module``,
|
|
|
|
``main_stream`` and ``main_code`` are NULL, this call does nothing.
|
|
|
|
|
|
|
|
If more than one of ``main_source``, ``main_path``, ``main_module``,
|
|
|
|
``main_stream`` or ``main_code`` are set, ``RuntimeError`` will be reported.
|
|
|
|
|
|
|
|
If ``main_code`` is already set, then this call does nothing.
|
|
|
|
|
|
|
|
If ``main_stream`` is set, and ``run_implicit_code`` is also set, then
|
|
|
|
the file identified in ``startup_file`` will be read, compiled and
|
|
|
|
executed in the ``__main__`` namespace.
|
|
|
|
|
|
|
|
If ``main_source``, ``main_path`` or ``main_module`` are set, then this
|
|
|
|
call will take whatever steps are needed to populate ``main_code``:
|
|
|
|
|
|
|
|
* For ``main_source``, the supplied string will be compiled and saved to
|
|
|
|
``main_code``.
|
|
|
|
|
|
|
|
* For ``main_path``:
|
2016-05-03 04:18:02 -04:00
|
|
|
|
|
|
|
* if the supplied path is recognised as a valid ``sys.path`` entry, it
|
|
|
|
is inserted as ``sys.path[0]``, ``main_module`` is set
|
|
|
|
to ``__main__`` and processing continues as for ``main_module`` below.
|
|
|
|
* otherwise, path is read as a CPython bytecode file
|
|
|
|
* if that fails, it is read as a Python source file and compiled
|
|
|
|
* in the latter two cases, the code object is saved to ``main_code``
|
|
|
|
and ``__main__.__file__`` is set appropriately
|
2013-01-13 01:35:06 -05:00
|
|
|
|
|
|
|
* For ``main_module``:
|
2016-05-03 04:18:02 -04:00
|
|
|
|
|
|
|
* any parent package is imported
|
|
|
|
* the loader for the module is determined
|
|
|
|
* if the loader indicates the module is a package, add ``.__main__`` to
|
|
|
|
the end of ``main_module`` and try again (if the final name segment
|
|
|
|
is already ``.__main__`` then fail immediately)
|
|
|
|
* once the module source code is located, save the compiled module code
|
|
|
|
as ``main_code`` and populate the following attributes in ``__main__``
|
|
|
|
appropriately: ``__name__``, ``__loader__``, ``__file__``,
|
|
|
|
``__cached__``, ``__package__``.
|
2013-01-13 01:35:06 -05:00
|
|
|
|
|
|
|
|
|
|
|
(Note: the behaviour described in this section isn't new, it's a write-up
|
|
|
|
of the current behaviour of the CPython interpreter adjusted for the new
|
|
|
|
configuration system)
|
|
|
|
|
|
|
|
|
2012-12-30 08:39:20 -05:00
|
|
|
Executing the main module
|
|
|
|
-------------------------
|
|
|
|
|
2022-01-21 06:03:51 -05:00
|
|
|
.. note:: In :pep:`587`, ``PyRun_PrepareMain`` and ``PyRun_ExecMain`` are not
|
2019-04-16 09:58:12 -04:00
|
|
|
exposed separately, and are instead accessed through a ``Py_RunMain`` API
|
|
|
|
that both prepares and executes main, and then finalizes the Python
|
|
|
|
interpreter.
|
|
|
|
|
|
|
|
|
2013-01-13 01:35:06 -05:00
|
|
|
This subphase covers the execution of the actual ``__main__`` module code.
|
2012-12-30 08:39:20 -05:00
|
|
|
|
2013-01-13 01:35:06 -05:00
|
|
|
It is handled by calling the following API::
|
2012-12-30 08:39:20 -05:00
|
|
|
|
2013-01-13 01:35:06 -05:00
|
|
|
int PyRun_ExecMain();
|
2012-12-30 08:39:20 -05:00
|
|
|
|
2015-06-30 07:43:19 -04:00
|
|
|
This operation is only permitted for the main interpreter, and will raise
|
|
|
|
``RuntimeError`` when invoked from a thread where the current thread state
|
|
|
|
belongs to a subinterpreter.
|
|
|
|
|
2013-01-13 01:35:06 -05:00
|
|
|
The actual processing is driven by the main related settings stored in
|
|
|
|
the interpreter state as part of the configuration struct.
|
|
|
|
|
|
|
|
If both ``main_stream`` and ``main_code`` are NULL, this call does nothing.
|
|
|
|
|
|
|
|
If both ``main_stream`` and ``main_code`` are set, ``RuntimeError`` will
|
|
|
|
be reported.
|
|
|
|
|
|
|
|
If ``main_stream`` and ``prompt_stream`` are both set, main execution will
|
2016-12-31 02:07:04 -05:00
|
|
|
be delegated to a new internal API::
|
2013-01-13 01:35:06 -05:00
|
|
|
|
2015-06-30 07:43:19 -04:00
|
|
|
int _PyRun_InteractiveMain(PyObject *input, PyObject* output);
|
2013-01-13 01:35:06 -05:00
|
|
|
|
|
|
|
If ``main_stream`` is set and ``prompt_stream`` is NULL, main execution will
|
2016-12-31 02:07:04 -05:00
|
|
|
be delegated to a new internal API::
|
2013-01-13 01:35:06 -05:00
|
|
|
|
2015-06-30 07:43:19 -04:00
|
|
|
int _PyRun_StreamInMain(PyObject *input);
|
2013-01-13 01:35:06 -05:00
|
|
|
|
2016-12-31 02:07:04 -05:00
|
|
|
If ``main_code`` is set, main execution will be delegated to a new internal
|
2013-01-13 01:35:06 -05:00
|
|
|
API::
|
|
|
|
|
2015-06-30 07:43:19 -04:00
|
|
|
int _PyRun_CodeInMain(PyCodeObject *code);
|
2013-01-13 01:35:06 -05:00
|
|
|
|
|
|
|
After execution of main completes, if ``inspect_main`` is set, or
|
|
|
|
the ``PYTHONINSPECT`` environment variable has been set, then
|
|
|
|
``PyRun_ExecMain`` will invoke
|
2015-06-30 07:43:19 -04:00
|
|
|
``_PyRun_InteractiveMain(sys.__stdin__, sys.__stdout__)``.
|
2013-01-02 06:25:24 -05:00
|
|
|
|
2012-12-30 08:39:20 -05:00
|
|
|
|
|
|
|
Internal Storage of Configuration Data
|
|
|
|
--------------------------------------
|
|
|
|
|
|
|
|
The interpreter state will be updated to include details of the configuration
|
|
|
|
settings supplied during initialization by extending the interpreter state
|
2019-04-16 09:58:12 -04:00
|
|
|
object with at least an embedded copy of the ``PyConfigAsObjects`` and
|
|
|
|
``PyInterpreterConfig`` structs.
|
2012-12-30 08:39:20 -05:00
|
|
|
|
2013-01-02 06:25:24 -05:00
|
|
|
For debugging purposes, the configuration settings will be exposed as
|
|
|
|
a ``sys._configuration`` simple namespace (similar to ``sys.flags`` and
|
2016-12-31 02:07:04 -05:00
|
|
|
``sys.implementation``. The attributes will be themselves by simple namespaces
|
2019-04-16 09:58:12 -04:00
|
|
|
corresponding to the two levels of configuration setting:
|
2016-12-31 02:07:04 -05:00
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
* ``all_interpreters``
|
|
|
|
* ``active_interpreter``
|
2016-12-31 02:07:04 -05:00
|
|
|
|
|
|
|
Field names will match those in the configuration structs, except for
|
|
|
|
``hash_seed``, which will be deliberately excluded.
|
2012-12-30 08:39:20 -05:00
|
|
|
|
2013-01-06 02:22:45 -05:00
|
|
|
An underscored attribute is chosen deliberately, as these configuration
|
|
|
|
settings are part of the CPython implementation, rather than part of the
|
2016-12-31 02:07:04 -05:00
|
|
|
Python language definition. If new settings are needed to support
|
2013-01-06 02:22:45 -05:00
|
|
|
cross-implementation compatibility in the standard library, then those
|
|
|
|
should be agreed with the other implementations and exposed as new required
|
2022-01-21 06:03:51 -05:00
|
|
|
attributes on ``sys.implementation``, as described in :pep:`421`.
|
2013-01-06 02:22:45 -05:00
|
|
|
|
2012-12-30 08:39:20 -05:00
|
|
|
These are *snapshots* of the initial configuration settings. They are not
|
2013-01-13 01:35:06 -05:00
|
|
|
modified by the interpreter during runtime (except as noted above).
|
2012-12-27 09:41:16 -05:00
|
|
|
|
|
|
|
|
2013-01-16 07:54:01 -05:00
|
|
|
Creating and Configuring Subinterpreters
|
|
|
|
----------------------------------------
|
|
|
|
|
|
|
|
As the new configuration settings are stored in the interpreter state, they
|
|
|
|
need to be initialised when a new subinterpreter is created. This turns out
|
2016-12-31 02:07:04 -05:00
|
|
|
to be trickier than one might expect due to ``PyThreadState_Swap(NULL);``
|
2013-01-16 07:54:01 -05:00
|
|
|
(which is fortunately exercised by CPython's own embedding tests, allowing
|
|
|
|
this problem to be detected during development).
|
|
|
|
|
|
|
|
To provide a straightforward solution for this case, the PEP proposes to
|
|
|
|
add a new API::
|
|
|
|
|
|
|
|
Py_InterpreterState *Py_InterpreterState_Main();
|
|
|
|
|
2016-12-31 02:07:04 -05:00
|
|
|
This will be a counterpart to ``Py_InterpreterState_Head()``, only reporting the
|
2013-01-16 07:54:01 -05:00
|
|
|
oldest currently existing interpreter rather than the newest. If
|
|
|
|
``Py_NewInterpreter()`` is called from a thread with an existing thread
|
|
|
|
state, then the interpreter configuration for that thread will be
|
|
|
|
used when initialising the new subinterpreter. If there is no current
|
|
|
|
thread state, the configuration from ``Py_InterpreterState_Main()``
|
|
|
|
will be used.
|
|
|
|
|
|
|
|
While the existing ``Py_InterpreterState_Head()`` API could be used instead,
|
|
|
|
that reference changes as subinterpreters are created and destroyed, while
|
|
|
|
``PyInterpreterState_Main()`` will always refer to the initial interpreter
|
2016-12-31 02:07:04 -05:00
|
|
|
state created in ``Py_InitializeRuntime()``.
|
2013-01-16 07:54:01 -05:00
|
|
|
|
|
|
|
A new constraint is also added to the embedding API: attempting to delete
|
|
|
|
the main interpreter while subinterpreters still exist will now be a fatal
|
|
|
|
error.
|
|
|
|
|
|
|
|
|
2012-12-27 09:41:16 -05:00
|
|
|
Stable ABI
|
|
|
|
----------
|
|
|
|
|
2013-01-13 01:35:06 -05:00
|
|
|
Most of the APIs proposed in this PEP are excluded from the stable ABI, as
|
2012-12-27 09:41:16 -05:00
|
|
|
embedding a Python interpreter involves a much higher degree of coupling
|
2016-12-31 02:07:04 -05:00
|
|
|
than merely writing an extension module.
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
The only newly exposed APIs that will be part of the stable ABI are the
|
|
|
|
``Py_IsInitializing()`` and ``Py_IsRuntimeInitialized()`` queries.
|
2013-01-13 01:35:06 -05:00
|
|
|
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2013-01-06 02:22:45 -05:00
|
|
|
Build time configuration
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
This PEP makes no changes to the handling of build time configuration
|
|
|
|
settings, and thus has no effect on the contents of ``sys.implementation``
|
|
|
|
or the result of ``sysconfig.get_config_vars()``.
|
|
|
|
|
|
|
|
|
2012-12-27 09:41:16 -05:00
|
|
|
Backwards Compatibility
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
Backwards compatibility will be preserved primarily by ensuring that
|
2019-04-16 09:58:12 -04:00
|
|
|
``Py_BuildPythonConfig()`` interrogates all the previously defined
|
2013-01-06 02:22:45 -05:00
|
|
|
configuration settings stored in global variables and environment variables,
|
2019-04-16 09:58:12 -04:00
|
|
|
and that ``Py_InitializeMainInterpreter()`` writes affected settings back to
|
2015-06-30 07:43:19 -04:00
|
|
|
the relevant locations.
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2016-07-11 11:14:08 -04:00
|
|
|
One acknowledged incompatibility is that some environment variables which
|
2012-12-27 09:41:16 -05:00
|
|
|
are currently read lazily may instead be read once during interpreter
|
2016-12-31 02:07:04 -05:00
|
|
|
initialization. As the reference implementation matures, these will be
|
2021-02-03 09:06:23 -05:00
|
|
|
discussed in more detail on a case-by-case basis. The environment variables
|
2016-12-31 02:07:04 -05:00
|
|
|
which are currently known to be looked up dynamically are:
|
2012-12-28 12:40:37 -05:00
|
|
|
|
|
|
|
* ``PYTHONCASEOK``: writing to ``os.environ['PYTHONCASEOK']`` will no longer
|
|
|
|
dynamically alter the interpreter's handling of filename case differences
|
|
|
|
on import (TBC)
|
|
|
|
* ``PYTHONINSPECT``: ``os.environ['PYTHONINSPECT']`` will still be checked
|
|
|
|
after execution of the ``__main__`` module terminates
|
|
|
|
|
2012-12-30 08:39:20 -05:00
|
|
|
The ``Py_Initialize()`` style of initialization will continue to be
|
2012-12-28 12:40:37 -05:00
|
|
|
supported. It will use (at least some elements of) the new API
|
|
|
|
internally, but will continue to exhibit the same behaviour as it
|
|
|
|
does today, ensuring that ``sys.argv`` is not populated until a subsequent
|
2016-12-31 02:07:04 -05:00
|
|
|
``PySys_SetArgv`` call (TBC). All APIs that currently support being called
|
2012-12-28 12:40:37 -05:00
|
|
|
prior to ``Py_Initialize()`` will
|
|
|
|
continue to do so, and will also support being called prior to
|
2016-12-31 02:07:04 -05:00
|
|
|
``Py_InitializeRuntime()``.
|
2012-12-27 09:41:16 -05:00
|
|
|
|
|
|
|
|
|
|
|
A System Python Executable
|
|
|
|
==========================
|
|
|
|
|
|
|
|
When executing system utilities with administrative access to a system, many
|
|
|
|
of the default behaviours of CPython are undesirable, as they may allow
|
|
|
|
untrusted code to execute with elevated privileges. The most problematic
|
|
|
|
aspects are the fact that user site directories are enabled,
|
|
|
|
environment variables are trusted and that the directory containing the
|
|
|
|
executed file is placed at the beginning of the import path.
|
|
|
|
|
2022-07-20 17:55:12 -04:00
|
|
|
Issue 16499 [6]_ added a ``-I`` option to change the behaviour of
|
2013-01-06 02:22:45 -05:00
|
|
|
the normal CPython executable, but this is a hard to discover solution (and
|
|
|
|
adds yet another option to an already complex CLI). This PEP proposes to
|
2015-12-27 06:44:47 -05:00
|
|
|
instead add a separate ``system-python`` executable
|
2013-01-06 02:22:45 -05:00
|
|
|
|
2012-12-27 09:41:16 -05:00
|
|
|
Currently, providing a separate executable with different default behaviour
|
|
|
|
would be prohibitively hard to maintain. One of the goals of this PEP is to
|
|
|
|
make it possible to replace much of the hard to maintain bootstrapping code
|
|
|
|
with more normal CPython code, as well as making it easier for a separate
|
|
|
|
application to make use of key components of ``Py_Main``. Including this
|
|
|
|
change in the PEP is designed to help avoid acceptance of a design that
|
|
|
|
sounds good in theory but proves to be problematic in practice.
|
|
|
|
|
2013-01-02 06:25:24 -05:00
|
|
|
Cleanly supporting this kind of "alternate CLI" is the main reason for the
|
2012-12-30 08:39:20 -05:00
|
|
|
proposed changes to better expose the core logic for deciding between the
|
2012-12-27 10:10:05 -05:00
|
|
|
different execution modes supported by CPython:
|
|
|
|
|
|
|
|
* script execution
|
|
|
|
* directory/zipfile execution
|
|
|
|
* command execution ("-c" switch)
|
|
|
|
* module or package execution ("-m" switch)
|
|
|
|
* execution from stdin (non-interactive)
|
|
|
|
* interactive stdin
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2013-01-06 02:22:45 -05:00
|
|
|
Actually implementing this may also reveal the need for some better
|
|
|
|
argument parsing infrastructure for use during the initializing phase.
|
|
|
|
|
|
|
|
|
|
|
|
Open Questions
|
|
|
|
==============
|
|
|
|
|
2019-04-16 09:58:12 -04:00
|
|
|
* Error details for ``Py_BuildPythonConfig`` and
|
|
|
|
``Py_InitializeMainInterpreter`` (these should become clearer as the
|
2015-06-30 07:43:19 -04:00
|
|
|
implementation progresses)
|
2013-01-06 02:22:45 -05:00
|
|
|
|
2012-12-27 09:41:16 -05:00
|
|
|
|
|
|
|
Implementation
|
|
|
|
==============
|
|
|
|
|
2019-03-02 21:17:22 -05:00
|
|
|
The reference implementation is being developed as a private API refactoring
|
|
|
|
within the CPython reference interpreter (as attempting to maintain it as an
|
|
|
|
independent project proved impractical).
|
2016-01-14 07:30:50 -05:00
|
|
|
|
2022-01-21 06:03:51 -05:00
|
|
|
:pep:`587` extracts a subset of the proposal that is considered sufficiently stable
|
2019-04-16 09:58:12 -04:00
|
|
|
to be worth proposing as a public API for Python 3.8.
|
|
|
|
|
2016-01-14 07:30:50 -05:00
|
|
|
|
2019-03-02 21:17:22 -05:00
|
|
|
The Status Quo (as of Python 3.6)
|
|
|
|
=================================
|
2013-01-15 06:50:35 -05:00
|
|
|
|
|
|
|
The current mechanisms for configuring the interpreter have accumulated in
|
|
|
|
a fairly ad hoc fashion over the past 20+ years, leading to a rather
|
|
|
|
inconsistent interface with varying levels of documentation.
|
|
|
|
|
2022-01-21 06:03:51 -05:00
|
|
|
Also see :pep:`587` for further discussion of the existing settings and their
|
2019-04-16 09:58:12 -04:00
|
|
|
handling.
|
|
|
|
|
2013-01-15 06:50:35 -05:00
|
|
|
(Note: some of the info below could probably be cleaned up and added to the
|
2019-03-02 21:17:22 -05:00
|
|
|
C API documentation for 3.x - it's all CPython specific, so it
|
2013-01-15 06:50:35 -05:00
|
|
|
doesn't belong in the language reference)
|
|
|
|
|
|
|
|
|
|
|
|
Ignoring Environment Variables
|
|
|
|
------------------------------
|
|
|
|
|
|
|
|
The ``-E`` command line option allows all environment variables to be
|
|
|
|
ignored when initializing the Python interpreter. An embedding application
|
|
|
|
can enable this behaviour by setting ``Py_IgnoreEnvironmentFlag`` before
|
|
|
|
calling ``Py_Initialize()``.
|
|
|
|
|
|
|
|
In the CPython source code, the ``Py_GETENV`` macro implicitly checks this
|
|
|
|
flag, and always produces ``NULL`` if it is set.
|
|
|
|
|
|
|
|
<TBD: I believe PYTHONCASEOK is checked regardless of this setting >
|
|
|
|
<TBD: Does -E also ignore Windows registry keys? >
|
|
|
|
|
|
|
|
|
|
|
|
Randomised Hashing
|
|
|
|
------------------
|
|
|
|
|
|
|
|
The randomised hashing is controlled via the ``-R`` command line option (in
|
|
|
|
releases prior to 3.3), as well as the ``PYTHONHASHSEED`` environment
|
|
|
|
variable.
|
|
|
|
|
|
|
|
In Python 3.3, only the environment variable remains relevant. It can be
|
|
|
|
used to disable randomised hashing (by using a seed value of 0) or else
|
|
|
|
to force a specific hash value (e.g. for repeatability of testing, or
|
|
|
|
to share hash values between processes)
|
|
|
|
|
|
|
|
However, embedding applications must use the ``Py_HashRandomizationFlag``
|
|
|
|
to explicitly request hash randomisation (CPython sets it in ``Py_Main()``
|
|
|
|
rather than in ``Py_Initialize()``).
|
|
|
|
|
|
|
|
The new configuration API should make it straightforward for an
|
|
|
|
embedding application to reuse the ``PYTHONHASHSEED`` processing with
|
|
|
|
a text based configuration setting provided by other means (e.g. a
|
|
|
|
config file or separate environment variable).
|
|
|
|
|
|
|
|
|
|
|
|
Locating Python and the standard library
|
|
|
|
----------------------------------------
|
|
|
|
|
|
|
|
The location of the Python binary and the standard library is influenced
|
|
|
|
by several elements. The algorithm used to perform the calculation is
|
2022-07-20 17:55:12 -04:00
|
|
|
not documented anywhere other than in the source code [3]_, [4]_. Even that
|
2013-01-15 06:50:35 -05:00
|
|
|
description is incomplete, as it failed to be updated for the virtual
|
2022-01-21 06:03:51 -05:00
|
|
|
environment support added in Python 3.3 (detailed in :pep:`405`).
|
2013-01-15 06:50:35 -05:00
|
|
|
|
|
|
|
These calculations are affected by the following function calls (made
|
|
|
|
prior to calling ``Py_Initialize()``) and environment variables:
|
|
|
|
|
|
|
|
* ``Py_SetProgramName()``
|
|
|
|
* ``Py_SetPythonHome()``
|
|
|
|
* ``PYTHONHOME``
|
|
|
|
|
2022-01-21 06:03:51 -05:00
|
|
|
The filesystem is also inspected for ``pyvenv.cfg`` files (see :pep:`405`) or,
|
2013-01-15 06:50:35 -05:00
|
|
|
failing that, a ``lib/os.py`` (Windows) or ``lib/python$VERSION/os.py``
|
|
|
|
file.
|
|
|
|
|
|
|
|
The build time settings for ``PREFIX`` and ``EXEC_PREFIX`` are also relevant,
|
|
|
|
as are some registry settings on Windows. The hardcoded fallbacks are
|
|
|
|
based on the layout of the CPython source tree and build output when
|
|
|
|
working in a source checkout.
|
|
|
|
|
|
|
|
|
|
|
|
Configuring ``sys.path``
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
An embedding application may call ``Py_SetPath()`` prior to
|
|
|
|
``Py_Initialize()`` to completely override the calculation of
|
|
|
|
``sys.path``. It is not straightforward to only allow *some* of the
|
|
|
|
calculations, as modifying ``sys.path`` after initialization is
|
|
|
|
already complete means those modifications will not be in effect
|
|
|
|
when standard library modules are imported during the startup sequence.
|
|
|
|
|
|
|
|
If ``Py_SetPath()`` is not used prior to the first call to ``Py_GetPath()``
|
|
|
|
(implicit in ``Py_Initialize()``), then it builds on the location data
|
|
|
|
calculations above to calculate suitable path entries, along with
|
|
|
|
the ``PYTHONPATH`` environment variable.
|
|
|
|
|
|
|
|
<TBD: On Windows, there's also a bunch of stuff to do with the registry>
|
|
|
|
|
|
|
|
The ``site`` module, which is implicitly imported at startup (unless
|
|
|
|
disabled via the ``-S`` option) adds additional paths to this initial
|
2022-07-20 17:55:12 -04:00
|
|
|
set of paths, as described in its documentation [5]_.
|
2013-01-15 06:50:35 -05:00
|
|
|
|
|
|
|
The ``-s`` command line option can be used to exclude the user site
|
|
|
|
directory from the list of directories added. Embedding applications
|
|
|
|
can control this by setting the ``Py_NoUserSiteDirectory`` global variable.
|
|
|
|
|
|
|
|
The following commands can be used to check the default path configurations
|
|
|
|
for a given Python executable on a given system:
|
|
|
|
|
|
|
|
* ``./python -c "import sys, pprint; pprint.pprint(sys.path)"``
|
|
|
|
- standard configuration
|
|
|
|
* ``./python -s -c "import sys, pprint; pprint.pprint(sys.path)"``
|
|
|
|
- user site directory disabled
|
|
|
|
* ``./python -S -c "import sys, pprint; pprint.pprint(sys.path)"``
|
|
|
|
- all site path modifications disabled
|
|
|
|
|
|
|
|
(Note: you can see similar information using ``-m site`` instead of ``-c``,
|
|
|
|
but this is slightly misleading as it calls ``os.abspath`` on all of the
|
|
|
|
path entries, making relative path entries look absolute. Using the ``site``
|
|
|
|
module also causes problems in the last case, as on Python versions prior to
|
|
|
|
3.3, explicitly importing site will carry out the path modifications ``-S``
|
|
|
|
avoids, while on 3.3+ combining ``-m site`` with ``-S`` currently fails)
|
|
|
|
|
|
|
|
The calculation of ``sys.path[0]`` is comparatively straightforward:
|
|
|
|
|
|
|
|
* For an ordinary script (Python source or compiled bytecode),
|
|
|
|
``sys.path[0]`` will be the directory containing the script.
|
|
|
|
* For a valid ``sys.path`` entry (typically a zipfile or directory),
|
|
|
|
``sys.path[0]`` will be that path
|
|
|
|
* For an interactive session, running from stdin or when using the ``-c`` or
|
|
|
|
``-m`` switches, ``sys.path[0]`` will be the empty string, which the import
|
|
|
|
system interprets as allowing imports from the current directory
|
|
|
|
|
|
|
|
|
|
|
|
Configuring ``sys.argv``
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
Unlike most other settings discussed in this PEP, ``sys.argv`` is not
|
|
|
|
set implicitly by ``Py_Initialize()``. Instead, it must be set via an
|
|
|
|
explicitly call to ``Py_SetArgv()``.
|
|
|
|
|
|
|
|
CPython calls this in ``Py_Main()`` after calling ``Py_Initialize()``. The
|
|
|
|
calculation of ``sys.argv[1:]`` is straightforward: they're the command line
|
|
|
|
arguments passed after the script name or the argument to the ``-c`` or
|
|
|
|
``-m`` options.
|
|
|
|
|
|
|
|
The calculation of ``sys.argv[0]`` is a little more complicated:
|
|
|
|
|
|
|
|
* For an ordinary script (source or bytecode), it will be the script name
|
|
|
|
* For a ``sys.path`` entry (typically a zipfile or directory) it will
|
|
|
|
initially be the zipfile or directory name, but will later be changed by
|
|
|
|
the ``runpy`` module to the full path to the imported ``__main__`` module.
|
|
|
|
* For a module specified with the ``-m`` switch, it will initially be the
|
|
|
|
string ``"-m"``, but will later be changed by the ``runpy`` module to the
|
|
|
|
full path to the executed module.
|
|
|
|
* For a package specified with the ``-m`` switch, it will initially be the
|
|
|
|
string ``"-m"``, but will later be changed by the ``runpy`` module to the
|
|
|
|
full path to the executed ``__main__`` submodule of the package.
|
|
|
|
* For a command executed with ``-c``, it will be the string ``"-c"``
|
|
|
|
* For explicitly requested input from stdin, it will be the string ``"-"``
|
|
|
|
* Otherwise, it will be the empty string
|
|
|
|
|
|
|
|
Embedding applications must call Py_SetArgv themselves. The CPython logic
|
|
|
|
for doing so is part of ``Py_Main()`` and is not exposed separately.
|
|
|
|
However, the ``runpy`` module does provide roughly equivalent logic in
|
|
|
|
``runpy.run_module`` and ``runpy.run_path``.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Other configuration settings
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
TBD: Cover the initialization of the following in more detail:
|
|
|
|
|
|
|
|
* Completely disabling the import system
|
|
|
|
* The initial warning system state:
|
2016-05-03 04:18:02 -04:00
|
|
|
|
2013-01-15 06:50:35 -05:00
|
|
|
* ``sys.warnoptions``
|
|
|
|
* (-W option, PYTHONWARNINGS)
|
2016-05-03 04:18:02 -04:00
|
|
|
|
2013-01-15 06:50:35 -05:00
|
|
|
* Arbitrary extended options (e.g. to automatically enable ``faulthandler``):
|
2016-05-03 04:18:02 -04:00
|
|
|
|
2013-01-15 06:50:35 -05:00
|
|
|
* ``sys._xoptions``
|
|
|
|
* (-X option)
|
2016-05-03 04:18:02 -04:00
|
|
|
|
2013-01-15 06:50:35 -05:00
|
|
|
* The filesystem encoding used by:
|
2016-05-03 04:18:02 -04:00
|
|
|
|
2013-01-15 06:50:35 -05:00
|
|
|
* ``sys.getfsencoding``
|
|
|
|
* ``os.fsencode``
|
|
|
|
* ``os.fsdecode``
|
2016-05-03 04:18:02 -04:00
|
|
|
|
2013-01-15 06:50:35 -05:00
|
|
|
* The IO encoding and buffering used by:
|
2016-05-03 04:18:02 -04:00
|
|
|
|
2013-01-15 06:50:35 -05:00
|
|
|
* ``sys.stdin``
|
|
|
|
* ``sys.stdout``
|
|
|
|
* ``sys.stderr``
|
|
|
|
* (-u option, PYTHONIOENCODING, PYTHONUNBUFFEREDIO)
|
2016-05-03 04:18:02 -04:00
|
|
|
|
2013-01-15 06:50:35 -05:00
|
|
|
* Whether or not to implicitly cache bytecode files:
|
2016-05-03 04:18:02 -04:00
|
|
|
|
2013-01-15 06:50:35 -05:00
|
|
|
* ``sys.dont_write_bytecode``
|
|
|
|
* (-B option, PYTHONDONTWRITEBYTECODE)
|
2016-05-03 04:18:02 -04:00
|
|
|
|
2013-01-15 06:50:35 -05:00
|
|
|
* Whether or not to enforce correct case in filenames on case-insensitive
|
|
|
|
platforms
|
2016-05-03 04:18:02 -04:00
|
|
|
|
2013-01-15 06:50:35 -05:00
|
|
|
* ``os.environ["PYTHONCASEOK"]``
|
2016-05-03 04:18:02 -04:00
|
|
|
|
2013-01-15 06:50:35 -05:00
|
|
|
* The other settings exposed to Python code in ``sys.flags``:
|
|
|
|
|
|
|
|
* ``debug`` (Enable debugging output in the pgen parser)
|
|
|
|
* ``inspect`` (Enter interactive interpreter after __main__ terminates)
|
|
|
|
* ``interactive`` (Treat stdin as a tty)
|
|
|
|
* ``optimize`` (__debug__ status, write .pyc or .pyo, strip doc strings)
|
|
|
|
* ``no_user_site`` (don't add the user site directory to sys.path)
|
|
|
|
* ``no_site`` (don't implicitly import site during startup)
|
|
|
|
* ``ignore_environment`` (whether environment vars are used during config)
|
|
|
|
* ``verbose`` (enable all sorts of random output)
|
|
|
|
* ``bytes_warning`` (warnings/errors for implicit str/bytes interaction)
|
|
|
|
* ``quiet`` (disable banner output even if verbose is also enabled or
|
|
|
|
stdin is a tty and the interpreter is launched in interactive mode)
|
|
|
|
|
|
|
|
* Whether or not CPython's signal handlers should be installed
|
|
|
|
|
|
|
|
Much of the configuration of CPython is currently handled through C level
|
|
|
|
global variables::
|
|
|
|
|
|
|
|
Py_BytesWarningFlag (-b)
|
|
|
|
Py_DebugFlag (-d option)
|
|
|
|
Py_InspectFlag (-i option, PYTHONINSPECT)
|
|
|
|
Py_InteractiveFlag (property of stdin, cannot be overridden)
|
|
|
|
Py_OptimizeFlag (-O option, PYTHONOPTIMIZE)
|
|
|
|
Py_DontWriteBytecodeFlag (-B option, PYTHONDONTWRITEBYTECODE)
|
|
|
|
Py_NoUserSiteDirectory (-s option, PYTHONNOUSERSITE)
|
|
|
|
Py_NoSiteFlag (-S option)
|
|
|
|
Py_UnbufferedStdioFlag (-u, PYTHONUNBUFFEREDIO)
|
|
|
|
Py_VerboseFlag (-v option, PYTHONVERBOSE)
|
|
|
|
|
|
|
|
For the above variables, the conversion of command line options and
|
|
|
|
environment variables to C global variables is handled by ``Py_Main``,
|
|
|
|
so each embedding application must set those appropriately in order to
|
|
|
|
change them from their defaults.
|
|
|
|
|
|
|
|
Some configuration can only be provided as OS level environment variables::
|
|
|
|
|
|
|
|
PYTHONSTARTUP
|
|
|
|
PYTHONCASEOK
|
|
|
|
PYTHONIOENCODING
|
|
|
|
|
|
|
|
The ``Py_InitializeEx()`` API also accepts a boolean flag to indicate
|
|
|
|
whether or not CPython's signal handlers should be installed.
|
|
|
|
|
|
|
|
Finally, some interactive behaviour (such as printing the introductory
|
|
|
|
banner) is triggered only when standard input is reported as a terminal
|
|
|
|
connection by the operating system.
|
|
|
|
|
|
|
|
TBD: Document how the "-x" option is handled (skips processing of the
|
|
|
|
first comment line in the main script)
|
|
|
|
|
2022-07-20 17:55:12 -04:00
|
|
|
Also see detailed sequence of operations notes at [1]_.
|
2013-01-15 06:50:35 -05:00
|
|
|
|
|
|
|
|
2012-12-27 09:41:16 -05:00
|
|
|
References
|
|
|
|
==========
|
|
|
|
|
|
|
|
.. [1] CPython interpreter initialization notes
|
|
|
|
(http://wiki.python.org/moin/CPythonInterpreterInitialization)
|
|
|
|
|
|
|
|
.. [2] BitBucket Sandbox
|
2013-01-12 09:48:28 -05:00
|
|
|
(https://bitbucket.org/ncoghlan/cpython_sandbox/compare/pep432_modular_bootstrap..default#commits)
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2012-12-28 12:40:37 -05:00
|
|
|
.. [3] \*nix getpath implementation
|
|
|
|
(http://hg.python.org/cpython/file/default/Modules/getpath.c)
|
|
|
|
|
|
|
|
.. [4] Windows getpath implementation
|
|
|
|
(http://hg.python.org/cpython/file/default/PC/getpathp.c)
|
|
|
|
|
|
|
|
.. [5] Site module documentation
|
|
|
|
(http://docs.python.org/3/library/site.html)
|
2012-12-27 09:41:16 -05:00
|
|
|
|
2013-01-06 02:22:45 -05:00
|
|
|
.. [6] Proposed CLI option for isolated mode
|
|
|
|
(http://bugs.python.org/issue16499)
|
|
|
|
|
|
|
|
.. [7] Adding to sys.path on the command line
|
2017-06-11 15:02:39 -04:00
|
|
|
(https://mail.python.org/pipermail/python-ideas/2010-October/008299.html)
|
|
|
|
(https://mail.python.org/pipermail/python-ideas/2012-September/016128.html)
|
2013-01-06 02:22:45 -05:00
|
|
|
|
|
|
|
.. [8] Control sys.path[0] initialisation
|
|
|
|
(http://bugs.python.org/issue13475)
|
|
|
|
|
|
|
|
.. [9] Enabling code coverage in subprocesses when testing
|
|
|
|
(http://bugs.python.org/issue14803)
|
|
|
|
|
|
|
|
.. [10] Problems with PYTHONIOENCODING in Blender
|
|
|
|
(http://bugs.python.org/issue16129)
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-27 09:41:16 -05:00
|
|
|
Copyright
|
|
|
|
===========
|
|
|
|
This document has been placed in the public domain.
|