@@ -166,7 +166,13 @@ def _run_in_threads(target, num_threads, parallel):
166166 thread .join ()
167167
168168
169+ # m.defined_THREAD_SANITIZER is used below to skip tests triggering this error (#2754):
170+ # ThreadSanitizer: starting new threads after multi-threaded fork is not supported.
171+
169172# TODO: FIXME, sometimes returns -11 (segfault) instead of 0 on macOS Python 3.9
173+ @pytest .mark .skipif (
174+ m .defined_THREAD_SANITIZER , reason = "Not compatible with ThreadSanitizer"
175+ )
170176@pytest .mark .parametrize ("test_fn" , ALL_BASIC_TESTS )
171177def test_run_in_process_one_thread (test_fn ):
172178 """Makes sure there is no GIL deadlock when running in a thread.
@@ -177,6 +183,9 @@ def test_run_in_process_one_thread(test_fn):
177183
178184
179185# TODO: FIXME on macOS Python 3.9
186+ @pytest .mark .skipif (
187+ m .defined_THREAD_SANITIZER , reason = "Not compatible with ThreadSanitizer"
188+ )
180189@pytest .mark .parametrize ("test_fn" , ALL_BASIC_TESTS )
181190def test_run_in_process_multiple_threads_parallel (test_fn ):
182191 """Makes sure there is no GIL deadlock when running in a thread multiple times in parallel.
@@ -190,6 +199,9 @@ def test_run_in_process_multiple_threads_parallel(test_fn):
190199
191200
192201# TODO: FIXME on macOS Python 3.9
202+ @pytest .mark .skipif (
203+ m .defined_THREAD_SANITIZER , reason = "Not compatible with ThreadSanitizer"
204+ )
193205@pytest .mark .parametrize ("test_fn" , ALL_BASIC_TESTS )
194206def test_run_in_process_multiple_threads_sequential (test_fn ):
195207 """Makes sure there is no GIL deadlock when running in a thread multiple times sequentially.
@@ -206,6 +218,14 @@ def test_run_in_process_direct(test_fn):
206218
207219 This test is for completion, but it was never an issue.
208220 """
221+ if m .defined_THREAD_SANITIZER and test_fn in (
222+ test_cross_module_gil_nested_custom_released ,
223+ test_cross_module_gil_nested_custom_acquired ,
224+ test_cross_module_gil_nested_pybind11_released ,
225+ test_cross_module_gil_nested_pybind11_acquired ,
226+ test_multi_acquire_release_cross_module ,
227+ ):
228+ pytest .skip ("Not compatible with ThreadSanitizer" )
209229 exitcode = _run_in_process (test_fn )
210230 if exitcode is None and env .PYPY and env .WIN : # Seems to be flaky.
211231 pytest .skip ("Ignoring unexpected exitcode None (PYPY WIN)" )
0 commit comments