Skip to content

Commit 3abad9f

Browse files
committed
test: add subinterpreters tests
1 parent a41f117 commit 3abad9f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/concurrent/test_subinterpreters.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,42 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
# ==============================================================================
15+
16+
import atexit
17+
import sys
18+
19+
import pytest
20+
21+
from helpers import (
22+
PYPY,
23+
WASM,
24+
Py_DEBUG,
25+
Py_GIL_DISABLED,
26+
)
27+
28+
29+
if PYPY or WASM or sys.version_info < (3, 14):
30+
pytest.skip('Test for CPython 3.14+ only', allow_module_level=True)
31+
32+
33+
from concurrent.futures import InterpreterPoolExecutor
34+
35+
36+
if Py_GIL_DISABLED and not Py_DEBUG:
37+
NUM_WORKERS = 32
38+
NUM_FUTURES = 128
39+
else:
40+
NUM_WORKERS = 4
41+
NUM_FUTURES = 16
42+
43+
44+
EXECUTOR = InterpreterPoolExecutor(max_workers=NUM_WORKERS)
45+
atexit.register(EXECUTOR.shutdown)
46+
47+
48+
def run(func, /, *args, **kwargs):
49+
future = EXECUTOR.submit(func, *args, **kwargs)
50+
exception = future.exception()
51+
if exception is not None:
52+
raise exception
53+
return future.result()

0 commit comments

Comments
 (0)