summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2024-08-17 20:04:08 (GMT)
committerGitHub <noreply@github.com>2024-08-17 20:04:08 (GMT)
commitd061ffea7b408861d0a9d311e92c363da284971d (patch)
tree669ad7db230f0d6e3004a36bab12f817f23a25b6 /Lib/test
parent40632b1f1da573f6d5e12453007474bcf70fba22 (diff)
downloadcpython-d061ffea7b408861d0a9d311e92c363da284971d.zip
cpython-d061ffea7b408861d0a9d311e92c363da284971d.tar.gz
cpython-d061ffea7b408861d0a9d311e92c363da284971d.tar.bz2
gh-123022: Fix crash with `Py_Initialize` in background thread (#123052)
Check that the current default heap is initialized in `_mi_os_get_aligned_hint` and `mi_os_claim_huge_pages`. The mimalloc function `_mi_os_get_aligned_hint` assumes that there is an initialized default heap. This is true for our main thread, but not for background threads. The problematic code path is usually called during initialization (i.e., `Py_Initialize`), but it may also be called if the program allocates large amounts of memory in total. The crash only affected the free-threaded build.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_embed.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py
index aab4333..7860c67 100644
--- a/Lib/test/test_embed.py
+++ b/Lib/test/test_embed.py
@@ -1,6 +1,6 @@
# Run the tests in Programs/_testembed.c (tests for the CPython embedding APIs)
from test import support
-from test.support import import_helper, os_helper, MS_WINDOWS
+from test.support import import_helper, os_helper, threading_helper, MS_WINDOWS
import unittest
from collections import namedtuple
@@ -1802,6 +1802,13 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
self.assertEqual(out, expected)
+ @threading_helper.requires_working_threading()
+ def test_init_in_background_thread(self):
+ # gh-123022: Check that running Py_Initialize() in a background
+ # thread doesn't crash.
+ out, err = self.run_embedded_interpreter("test_init_in_background_thread")
+ self.assertEqual(err, "")
+
class SetConfigTests(unittest.TestCase):
def test_set_config(self):