summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorPeter Bierma <zintensitydev@gmail.com>2024-12-06 15:58:19 (GMT)
committerGitHub <noreply@github.com>2024-12-06 15:58:19 (GMT)
commit12680ec5bd45c85b6daebe0739d30ef45f089efa (patch)
treea94a35fc4e7fbb5daf875c5142d50a89e595d957 /Lib
parenta353455fca1b8f468ff3ffbb4b5e316510b4fd43 (diff)
downloadcpython-12680ec5bd45c85b6daebe0739d30ef45f089efa.zip
cpython-12680ec5bd45c85b6daebe0739d30ef45f089efa.tar.gz
cpython-12680ec5bd45c85b6daebe0739d30ef45f089efa.tar.bz2
gh-127314: Don't mention the GIL when calling without a thread state on the free-threaded build (#127315)
Co-authored-by: Victor Stinner <vstinner@python.org>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_capi/test_mem.py9
-rw-r--r--Lib/test/test_capi/test_misc.py17
2 files changed, 19 insertions, 7 deletions
diff --git a/Lib/test/test_capi/test_mem.py b/Lib/test/test_capi/test_mem.py
index 6ab7b68..5035b2b 100644
--- a/Lib/test/test_capi/test_mem.py
+++ b/Lib/test/test_capi/test_mem.py
@@ -68,8 +68,13 @@ class PyMemDebugTests(unittest.TestCase):
def check_malloc_without_gil(self, code):
out = self.check(code)
- expected = ('Fatal Python error: _PyMem_DebugMalloc: '
- 'Python memory allocator called without holding the GIL')
+ if not support.Py_GIL_DISABLED:
+ expected = ('Fatal Python error: _PyMem_DebugMalloc: '
+ 'Python memory allocator called without holding the GIL')
+ else:
+ expected = ('Fatal Python error: _PyMem_DebugMalloc: '
+ 'Python memory allocator called without an active thread state. '
+ 'Are you trying to call it inside of a Py_BEGIN_ALLOW_THREADS block?')
self.assertIn(expected, out)
def test_pymem_malloc_without_gil(self):
diff --git a/Lib/test/test_capi/test_misc.py b/Lib/test/test_capi/test_misc.py
index 8e02719..61512e6 100644
--- a/Lib/test/test_capi/test_misc.py
+++ b/Lib/test/test_capi/test_misc.py
@@ -100,11 +100,18 @@ class CAPITest(unittest.TestCase):
_rc, out, err = run_result
self.assertEqual(out, b'')
# This used to cause an infinite loop.
- msg = ("Fatal Python error: PyThreadState_Get: "
- "the function must be called with the GIL held, "
- "after Python initialization and before Python finalization, "
- "but the GIL is released "
- "(the current Python thread state is NULL)").encode()
+ if not support.Py_GIL_DISABLED:
+ msg = ("Fatal Python error: PyThreadState_Get: "
+ "the function must be called with the GIL held, "
+ "after Python initialization and before Python finalization, "
+ "but the GIL is released "
+ "(the current Python thread state is NULL)").encode()
+ else:
+ msg = ("Fatal Python error: PyThreadState_Get: "
+ "the function must be called with an active thread state, "
+ "after Python initialization and before Python finalization, "
+ "but it was called without an active thread state. "
+ "Are you trying to call the C API inside of a Py_BEGIN_ALLOW_THREADS block?").encode()
self.assertTrue(err.rstrip().startswith(msg),
err)