Makes sure the internals object differs across subinterpreters
()
| 184 | sys.platform.startswith("emscripten"), reason="Requires loadable modules" |
| 185 | ) |
| 186 | def 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 | |
| 216 | PREAMBLE_CODE = textwrap.dedent( |
nothing calls this directly
no test coverage detected