MCPcopy Create free account
hub / github.com/pybind/pybind11 / test_dependent_subinterpreters

Function test_dependent_subinterpreters

tests/test_multiple_interpreters.py:186–213  ·  view source on GitHub ↗

Makes sure the internals object differs across subinterpreters

()

Source from the content-addressed store, hash-verified

184 sys.platform.startswith("emscripten"), reason="Requires loadable modules"
185)
186def test_dependent_subinterpreters():
187 """Makes sure the internals object differs across subinterpreters"""
188
189 sys.path.insert(0, os.path.dirname(pybind11_tests.__file__))
190
191 run_string, create = get_interpreters(modern=False)
192
193 import mod_shared_interpreter_gil as m
194
195 if not m.defined_PYBIND11_HAS_SUBINTERPRETER_SUPPORT:
196 pytest.skip("Does not have subinterpreter support compiled in")
197
198 code = textwrap.dedent(
199 """
200 import mod_shared_interpreter_gil as m
201 import pickle
202 with open(pipeo, 'wb') as f:
203 pickle.dump(m.internals_at(), f)
204 """
205 ).strip()
206
207 with create("legacy") as interp1:
208 pipei, pipeo = os.pipe()
209 run_string(interp1, code, shared={"pipeo": pipeo})
210 with open(pipei, "rb") as f:
211 res1 = pickle.load(f)
212
213 assert res1 != m.internals_at(), "internals should differ from main interpreter"
214
215
216PREAMBLE_CODE = textwrap.dedent(

Callers

nothing calls this directly

Calls 5

get_interpretersFunction · 0.85
createFunction · 0.85
run_stringFunction · 0.85
insertMethod · 0.80
loadMethod · 0.45

Tested by

no test coverage detected