Skip to content

Commit 31d5fa4

Browse files
committed
tests: try to fix beta2
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 1ce6ed5 commit 31d5fa4

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

tests/test_multiple_interpreters.py

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99

1010
CONCURRENT_INTERPRETERS_SUPPORT = sys.version_info >= (3, 14) and (
1111
sys.version_info != (3, 14, 0, "beta", 1)
12-
or sys.version_info != (3, 14, 0, "beta", 2)
12+
and sys.version_info != (3, 14, 0, "beta", 2)
1313
)
1414

1515

1616
def get_interpreters(*, modern: bool):
1717
if modern and CONCURRENT_INTERPRETERS_SUPPORT:
18+
print(sys.version_info)
1819
from concurrent import interpreters
1920

2021
def create():
@@ -129,6 +130,65 @@ def test_independent_subinterpreters():
129130
)
130131

131132

133+
@pytest.mark.skipif(
134+
sys.platform.startswith("emscripten"), reason="Requires loadable modules"
135+
)
136+
@pytest.mark.skipif(not CONCURRENT_INTERPRETERS_SUPPORT, reason="Requires 3.14.0b3+")
137+
def test_independent_subinterpreters_modern():
138+
"""Makes sure the internals object differs across independent subinterpreters. Modern (3.14+) syntax."""
139+
140+
sys.path.append(".")
141+
142+
m = pytest.importorskip("mod_per_interpreter_gil")
143+
144+
if not m.defined_PYBIND11_HAS_SUBINTERPRETER_SUPPORT:
145+
pytest.skip("Does not have subinterpreter support compiled in")
146+
147+
from concurrent import interpreters
148+
149+
code = """
150+
import mod_per_interpreter_gil as m
151+
152+
values.put_nowait(m.internals_at())
153+
"""
154+
155+
with contextlib.closing(interpreters.create()) as interp1, contextlib.closing(
156+
interpreters.create()
157+
) as interp2:
158+
with pytest.raises(
159+
interpreters.ExecutionFailed,
160+
match="does not support loading in subinterpreters",
161+
):
162+
interp1.exec("import mod_shared_interpreter_gil")
163+
164+
values = interpreters.create_queue()
165+
interp1.prepare_main(values=values)
166+
interp1.exec(code)
167+
res1 = values.get_nowait()
168+
169+
interp2.prepare_main(values=values)
170+
interp2.exec(code)
171+
res2 = values.get_nowait()
172+
173+
# do this while the two interpreters are active
174+
import mod_per_interpreter_gil as m2
175+
176+
assert m.internals_at() == m2.internals_at(), (
177+
"internals should be the same within the main interpreter"
178+
)
179+
180+
assert res1 != m.internals_at(), "internals should differ from main interpreter"
181+
assert res2 != m.internals_at(), "internals should differ from main interpreter"
182+
assert res1 != res2, "internals should differ between interpreters"
183+
184+
# do this after the two interpreters are destroyed and only one remains
185+
import mod_per_interpreter_gil as m3
186+
187+
assert m.internals_at() == m3.internals_at(), (
188+
"internals should be the same within the main interpreter"
189+
)
190+
191+
132192
@pytest.mark.skipif(
133193
sys.platform.startswith("emscripten"), reason="Requires loadable modules"
134194
)

0 commit comments

Comments
 (0)