Tracks the development and state of supporting sub-interpreters in PyO3.
This issue really only tracks progress, for discussing everything else, feel free to join over here: Aequitosh#1
Summary
As of 13.09.2023
PyO3 currently doesn't support sub-interpreters, which will lead to an ImportError being raised if a module using PyO3 is initialized more than once per interpreter process. As stated in #2523, this is necessary in order to prevent soundness holes (as in, prevent things that use PyO3 from randomly breaking, having nasty undefined behaviour, etc.).
Even though this prevents soundness holes on the one hand, it can lead to modules / applications using a sub-interpreter model to "break" in certain situations. For examples, see pyca/cryptography#9016 and bazaah/aur-ceph#20.
Implementing sub-interpreter support isn't straightforward and requires quite a substantial redesign of PyO3's API. This issue shall track this redesign and provide as much relevant information as possible for all that wish to contribute.
Goals
Adapted from #576 (comment), as of 13.09.2023.
Mid-Term
Long-Term
Possibly remove the need for extension authors to audit their own code once we're confident enough.
Tasks
TBA - might them here (or some other place) once more concrete pieces of work have been identified.
Relevant Issues & Interesting Reads
Listing relevant things here. Some things might already be linked above, but it's nevertheless nice to have everything in one place.
Tracks the development and state of supporting sub-interpreters in PyO3.
This issue really only tracks progress, for discussing everything else, feel free to join over here: Aequitosh#1
Summary
As of 13.09.2023
PyO3 currently doesn't support sub-interpreters, which will lead to an
ImportErrorbeing raised if a module using PyO3 is initialized more than once per interpreter process. As stated in #2523, this is necessary in order to prevent soundness holes (as in, prevent things that use PyO3 from randomly breaking, having nasty undefined behaviour, etc.).Even though this prevents soundness holes on the one hand, it can lead to modules / applications using a sub-interpreter model to "break" in certain situations. For examples, see pyca/cryptography#9016 and bazaah/aur-ceph#20.
Implementing sub-interpreter support isn't straightforward and requires quite a substantial redesign of PyO3's API. This issue shall track this redesign and provide as much relevant information as possible for all that wish to contribute.
Goals
Adapted from #576 (comment), as of 13.09.2023.
Mid-Term
staticdata from PyO3's implementation, either move things toPyModule_GetState(preferred) orPyInterpreterState_GetDict(alternative)unsafein order to opt in to sub-interpreter support - it is their responsibility to guarantee to not storePy<T>in any static data.Long-Term
Possibly remove the need for extension authors to audit their own code once we're confident enough.
Tasks
TBA - might them here (or some other place) once more concrete pieces of work have been identified.
Relevant Issues & Interesting Reads
Listing relevant things here. Some things might already be linked above, but it's nevertheless nice to have everything in one place.
Support sub-interpreters #576
Add support for nogil Python #2885
How can we make Python's C-API more friendly for Rust? #2346 (comment)
cryptographyissue regarding sub-interpreters in PyO3:Different behaviour between 41.0.0, 41.0.1 and 40.0.2 - PyO3 modules may only be initialized once per interpreter process pyca/cryptography#9016
aur-cephmaintainer's issue regarding Ceph's sub-interpreter model, and why Ceph Dashboard breaks:ceph-mgr/dashboard: python-cryptography PyO3 modules may only be initialized once per interpreter process bazaah/aur-ceph#20
ghostcell-ish pattern:Support sub-interpreters #576 (comment)