Skip to content

Commit adda43d

Browse files
gh-105699: Add some stress tests for subinterpreter creation (#106966)
1 parent ed491d9 commit adda43d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Lib/test/test_interpreters.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from test import support
99
from test.support import import_helper
10+
from test.support import threading_helper
1011
_interpreters = import_helper.import_module('_xxsubinterpreters')
1112
_channels = import_helper.import_module('_xxinterpchannels')
1213
from test.support import interpreters
@@ -463,6 +464,27 @@ def test_bytes_for_script(self):
463464
# test_xxsubinterpreters covers the remaining Interpreter.run() behavior.
464465

465466

467+
class StressTests(TestBase):
468+
469+
# In these tests we generally want a lot of interpreters,
470+
# but not so many that any test takes too long.
471+
472+
def test_create_many_sequential(self):
473+
alive = []
474+
for _ in range(100):
475+
interp = interpreters.create()
476+
alive.append(interp)
477+
478+
def test_create_many_threaded(self):
479+
alive = []
480+
def task():
481+
interp = interpreters.create()
482+
alive.append(interp)
483+
threads = (threading.Thread(target=task) for _ in range(200))
484+
with threading_helper.start_threads(threads):
485+
pass
486+
487+
466488
class TestIsShareable(TestBase):
467489

468490
def test_default_shareables(self):

0 commit comments

Comments
 (0)