Skip to content
/ pyo3 Public
forked from PyO3/pyo3

Commit 8b5ce7c

Browse files
bazaahzer0def
authored and
zer0def
committed
src/impl_: add ff unsafe-allow-subinterpreters
Allow the subinterpreter safeguards to be disabled, so that applications like Ceph's manager can continue to use pyo3 modules without soft crashing. Enabling this feature should be done with caution, as any storage of Py objects in rust statics can lead to undefined behavior. However, not all consumers of pyo3 use global state, and thus a subset of them (such as python-bcrypt) are safe to use in subinterpreter contexts. References: bazaah/aur-ceph#20 References: PyO3#2523 References: pyca/cryptography#9016 References: PyO3#2346 (comment) References: PyO3#2346 (comment) References: PyO3#3451 Signed-off-by: Paul Stemmet <[email protected]>
1 parent a967826 commit 8b5ce7c

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ py-clone = []
112112
# Optimizes PyObject to Vec conversion and so on.
113113
nightly = []
114114

115+
# Disables the checks for use in subinterpreters.
116+
unsafe-allow-subinterpreters = []
117+
115118
# Activates all additional features
116119
# This is mostly intended for testing purposes - activating *all* of these isn't particularly useful.
117120
full = [

src/impl_/pymodule.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl ModuleDef {
100100
// that static data is not reused across interpreters.
101101
//
102102
// PyPy does not have subinterpreters, so no need to check interpreter ID.
103-
#[cfg(not(any(PyPy, GraalPy)))]
103+
#[cfg(not(any(PyPy, GraalPy, feature = "unsafe-allow-subinterpreters")))]
104104
{
105105
// PyInterpreterState_Get is only available on 3.9 and later, but is missing
106106
// from python3.dll for Windows stable API on 3.9

0 commit comments

Comments
 (0)