[3.14] gh-140260: fix data race in _struct module initialization with subinterpreters (GH-140909) (#141501)

gh-140260: fix data race in `_struct` module initialization with subinterpreters (GH-140909)
(cherry picked from commit 63548b3699)

Co-authored-by: Shamil <ashm.tech@proton.me>
This commit is contained in:
Miss Islington (bot) 2025-11-13 12:53:22 +01:00 committed by GitHub
parent 7e9400c3e6
commit 79195df23c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 70 additions and 41 deletions

View file

@ -800,6 +800,23 @@ def test_c_complex_round_trip(self):
round_trip = struct.unpack(f, struct.pack(f, z))[0]
self.assertComplexesAreIdentical(z, round_trip)
@unittest.skipIf(
support.is_android or support.is_apple_mobile,
"Subinterpreters are not supported on Android and iOS"
)
def test_endian_table_init_subinterpreters(self):
# Verify that the _struct extension module can be initialized
# concurrently in subinterpreters (gh-140260).
try:
from concurrent.futures import InterpreterPoolExecutor
except ImportError:
raise unittest.SkipTest("InterpreterPoolExecutor not available")
code = "import struct"
with InterpreterPoolExecutor(max_workers=5) as executor:
results = executor.map(exec, [code] * 5)
self.assertListEqual(list(results), [None] * 5)
class UnpackIteratorTest(unittest.TestCase):
"""