9 from pybind11_tests
import gil_scoped
as m
13 """Runs target in process and returns its exitcode after 10s (None if still alive).""" 14 process = multiprocessing.Process(target=target, args=args, kwargs=kwargs)
19 process.join(timeout=10)
20 return process.exitcode
22 if process.is_alive():
27 """Calls different C++ functions that come back to Python.""" 28 class ExtendedVirtClass(m.VirtClass):
29 def virtual_func(self):
32 def pure_virtual_func(self):
35 extended = ExtendedVirtClass()
36 m.test_callback_py_obj(
lambda:
None)
37 m.test_callback_std_func(
lambda:
None)
38 m.test_callback_virtual_func(extended)
39 m.test_callback_pure_virtual_func(extended)
43 """Calls different C++ functions that come back to Python, from Python threads.""" 45 for _
in range(num_threads):
46 thread = threading.Thread(target=_python_to_cpp_to_python)
50 threads.append(thread)
53 for thread
in threads:
58 @pytest.mark.xfail(
"env.PY > (3,8) and env.MACOS", strict=
False)
60 """Makes sure there is no GIL deadlock when running in a thread. 62 It runs in a separate process to be able to stop and assert if it deadlocks. 68 @pytest.mark.xfail(
"env.PY > (3,8) and env.MACOS", strict=
False)
70 """Makes sure there is no GIL deadlock when running in a thread multiple times in parallel. 72 It runs in a separate process to be able to stop and assert if it deadlocks. 74 assert _run_in_process(_python_to_cpp_to_python_from_threads, 8, parallel=
True) == 0
78 @pytest.mark.xfail(
"env.PY > (3,8) and env.MACOS", strict=
False)
80 """Makes sure there is no GIL deadlock when running in a thread multiple times sequentially. 82 It runs in a separate process to be able to stop and assert if it deadlocks. 84 assert _run_in_process(_python_to_cpp_to_python_from_threads, 8, parallel=
False) == 0
88 @pytest.mark.xfail(
"env.PY > (3,8) and env.MACOS", strict=
False)
90 """Makes sure there is no GIL deadlock when using processes. 92 This test is for completion, but it was never an issue. 98 """Makes sure that the GIL can be acquired by another module from a GIL-released state.""" 99 m.test_cross_module_gil()
def _run_in_process(target, args, kwargs)
def test_python_to_cpp_to_python_from_thread_multiple_parallel()
def _python_to_cpp_to_python()
def test_python_to_cpp_to_python_from_process()
def _python_to_cpp_to_python_from_threads(num_threads, parallel=False)
def test_cross_module_gil()
def test_python_to_cpp_to_python_from_thread_multiple_sequential()
def test_python_to_cpp_to_python_from_thread()