From 4c19a9ae8d1b4beb19b5c4fa4436d6a14cb399e4 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Sat, 29 Oct 2022 20:16:02 -0700 Subject: [PATCH] Wrap m.intentional_deadlock in a Python function, for `ForkingPickler` compatibility. ``` > ForkingPickler(file, protocol).dump(obj) E TypeError: cannot pickle 'PyCapsule' object ``` Observed with all Windows builds including mingw but not PyPy, and macos-latest with Python 3.9, 3.10, 3.11 but not 3.6. --- tests/test_gil_scoped.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/test_gil_scoped.py b/tests/test_gil_scoped.py index 526745ee5e..5f4510e4a7 100644 --- a/tests/test_gil_scoped.py +++ b/tests/test_gil_scoped.py @@ -138,7 +138,11 @@ def test_all_basic_tests_completeness(): assert len(ALL_BASIC_TESTS) == num_found -ALL_BASIC_TESTS_PLUS_INTENTIONAL_DEADLOCK = ALL_BASIC_TESTS + (m.intentional_deadlock,) +def _intentional_deadlock(): + m.intentional_deadlock() + + +ALL_BASIC_TESTS_PLUS_INTENTIONAL_DEADLOCK = ALL_BASIC_TESTS + (_intentional_deadlock,) def _run_in_process(target, *args, **kwargs): @@ -147,7 +151,7 @@ def _run_in_process(target, *args, **kwargs): else: test_fn = args[0] # Do not need to wait much, 10s should be more than enough. - timeout = 0.1 if test_fn is m.intentional_deadlock else 10 + timeout = 0.1 if test_fn is _intentional_deadlock else 10 process = multiprocessing.Process(target=target, args=args, kwargs=kwargs) process.daemon = True try: @@ -164,7 +168,7 @@ def _run_in_process(target, *args, **kwargs): pytest.skip( "ThreadSanitizer: starting new threads after multi-threaded fork is not supported." ) - elif test_fn is m.intentional_deadlock: + elif test_fn is _intentional_deadlock: assert process.exitcode is None return 0 elif process.exitcode is None: