Python: Different native runtime state tiers.
CPython at the very least has 2 different type of native states: Interpreter & Module state. Unfortunately, the multi-phase initialization has a weakness when it comes to Module states. You can't access the module state without a pointer to the module. PyState_GetModule from a standpoint looks to be the obvious answer to use, but it's documentation states it's unfit for multi-phase initialization. I'm proposing an idea here for discussion on a new state system for at least CPython. Tier 1: Core state - This state lives within CPython's core binary and exists the entire lifetime of the binary. - The data held within this state is available to the main interpreter and subsequent sub-interpreters. (Example: sys.executable) Tier 2-1: Interpreter state (Branches from Core state) - This state lives within CPython's core binary and is tied to a specific interpreter. - The data held within this state is only available to the interpreter it's tied to. (Example: Modules loaded into memory) Tier 2-2: Extension state (Branches from Core state) - This state lives within any CPython's core binary EXCEPT it's size and structure is defined by the extension CPython has loaded. - The purpose of this state is to allow an extension to hold data that can't be tied to a specific module. (Examples can be: Windows WSA, MySQL) Tier 3-1: Thread state (Branches from Interpreter State) - This state lives within CPython's core binary and is tied to a specific Python thread (IE: Threading library threads), - The data held within this state is only available to the thread it's tied to. (No known examples available) Tier 3-2: Module state (Branches from Interpreter State) - This type of state is already available in CPython, explaining it is not required.
You might fine more interest on the Python C-API mailing list. https://mail.python.org/mailman3/lists/capi-sig.python.org/ <https://mail.python.org/mailman3/lists/capi-sig.python.org/> Barry
On 8 Jul 2020, at 23:58, William Pickard <lollol222gg@gmail.com> wrote:
CPython at the very least has 2 different type of native states: Interpreter & Module state. Unfortunately, the multi-phase initialization has a weakness when it comes to Module states.
You can't access the module state without a pointer to the module. PyState_GetModule from a standpoint looks to be the obvious answer to use, but it's documentation states it's unfit for multi-phase initialization.
I'm proposing an idea here for discussion on a new state system for at least CPython.
Tier 1: Core state - This state lives within CPython's core binary and exists the entire lifetime of the binary. - The data held within this state is available to the main interpreter and subsequent sub-interpreters. (Example: sys.executable)
Tier 2-1: Interpreter state (Branches from Core state) - This state lives within CPython's core binary and is tied to a specific interpreter. - The data held within this state is only available to the interpreter it's tied to. (Example: Modules loaded into memory)
Tier 2-2: Extension state (Branches from Core state) - This state lives within any CPython's core binary EXCEPT it's size and structure is defined by the extension CPython has loaded. - The purpose of this state is to allow an extension to hold data that can't be tied to a specific module. (Examples can be: Windows WSA, MySQL)
Tier 3-1: Thread state (Branches from Interpreter State) - This state lives within CPython's core binary and is tied to a specific Python thread (IE: Threading library threads), - The data held within this state is only available to the thread it's tied to. (No known examples available)
Tier 3-2: Module state (Branches from Interpreter State) - This type of state is already available in CPython, explaining it is not required. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/FEL2CW... Code of Conduct: http://python.org/psf/codeofconduct/
participants (2)
-
Barry Scott
-
William Pickard