1- import builtins
21import multiprocessing
32import threading
43
5- import pytest
6-
74from pybind11_tests import gil_scoped as m
85
96
10- def get_pybind11_internals_keys ():
11- keys = []
12- for key in dir (builtins ):
13- if key .startswith ("__pybind11_internals_" ):
14- assert key .endswith ("__" )
15- keys .append (key )
16- return tuple (sorted (keys ))
17-
18-
197def _run_in_process (target , * args , ** kwargs ):
208 """Runs target in process and returns its exitcode after 10s (None if still alive)."""
219 process = multiprocessing .Process (target = target , args = args , kwargs = kwargs )
@@ -45,6 +33,7 @@ def pure_virtual_func(self):
4533 m .test_callback_std_func (lambda : None )
4634 m .test_callback_virtual_func (extended )
4735 m .test_callback_pure_virtual_func (extended )
36+
4837 m .test_cross_module_gil_released ()
4938 m .test_cross_module_gil_acquired ()
5039 m .test_cross_module_gil_inner_custom_released ()
@@ -54,10 +43,15 @@ def pure_virtual_func(self):
5443 m .test_cross_module_gil_nested_custom_released ()
5544 m .test_cross_module_gil_nested_custom_acquired ()
5645 m .test_cross_module_gil_nested_pybind11_released ()
57- # m.test_cross_module_gil_nested_pybind11_acquire() # this one dies in test_python_to_cpp_to_python_from_process
46+ m .test_cross_module_gil_nested_pybind11_acquired ()
47+
5848 assert m .test_release_acquire (0xAB ) == "171"
5949 assert m .test_nested_acquire (0xAB ) == "171"
6050
51+ for bits in range (16 * 8 ):
52+ internals_ids = m .test_multi_acquire_release_cross_module (bits )
53+ assert len (internals_ids ) == 2 if bits % 8 else 1
54+
6155
6256def _python_to_cpp_to_python_from_threads (num_threads , parallel = False ):
6357 """Calls different C++ functions that come back to Python, from Python threads."""
@@ -122,14 +116,6 @@ def test_cross_module_gil_acquired():
122116 m .test_cross_module_gil_acquired () # Should not raise a SIGSEGV
123117
124118
125- def test_report_builtins_internals_keys ():
126- """For reporting, not an actual test."""
127- m .test_cross_module_gil_released () # Any test that imports cross_module_gil_utils
128- keys = get_pybind11_internals_keys ()
129- assert len (keys ) != 0
130- pytest .skip ("builtins internals keys: %s" % ", " .join (keys ))
131-
132-
133119def test_cross_module_gil_inner_custom_released ():
134120 """Makes sure that the GIL can be acquired/released by another module
135121 from a GIL-released state using custom locking logic."""
@@ -184,3 +170,9 @@ def test_release_acquire():
184170
185171def test_nested_acquire ():
186172 assert m .test_nested_acquire (0xAB ) == "171"
173+
174+
175+ def test_multi_acquire_release_cross_module ():
176+ for bits in range (16 * 8 ):
177+ internals_ids = m .test_multi_acquire_release_cross_module (bits )
178+ assert len (internals_ids ) == 2 if bits % 8 else 1
0 commit comments