1
- import builtins
2
1
import multiprocessing
3
2
import threading
4
3
5
- import pytest
6
-
7
4
from pybind11_tests import gil_scoped as m
8
5
9
6
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
-
19
7
def _run_in_process (target , * args , ** kwargs ):
20
8
"""Runs target in process and returns its exitcode after 10s (None if still alive)."""
21
9
process = multiprocessing .Process (target = target , args = args , kwargs = kwargs )
@@ -45,6 +33,7 @@ def pure_virtual_func(self):
45
33
m .test_callback_std_func (lambda : None )
46
34
m .test_callback_virtual_func (extended )
47
35
m .test_callback_pure_virtual_func (extended )
36
+
48
37
m .test_cross_module_gil_released ()
49
38
m .test_cross_module_gil_acquired ()
50
39
m .test_cross_module_gil_inner_custom_released ()
@@ -54,10 +43,15 @@ def pure_virtual_func(self):
54
43
m .test_cross_module_gil_nested_custom_released ()
55
44
m .test_cross_module_gil_nested_custom_acquired ()
56
45
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
+
58
48
assert m .test_release_acquire (0xAB ) == "171"
59
49
assert m .test_nested_acquire (0xAB ) == "171"
60
50
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
+
61
55
62
56
def _python_to_cpp_to_python_from_threads (num_threads , parallel = False ):
63
57
"""Calls different C++ functions that come back to Python, from Python threads."""
@@ -122,14 +116,6 @@ def test_cross_module_gil_acquired():
122
116
m .test_cross_module_gil_acquired () # Should not raise a SIGSEGV
123
117
124
118
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
-
133
119
def test_cross_module_gil_inner_custom_released ():
134
120
"""Makes sure that the GIL can be acquired/released by another module
135
121
from a GIL-released state using custom locking logic."""
@@ -184,3 +170,9 @@ def test_release_acquire():
184
170
185
171
def test_nested_acquire ():
186
172
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