https://github.com/python/cpython/commit/ba10100c3931b18812b82d7124e2238f01927910
commit: ba10100c3931b18812b82d7124e2238f01927910
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-01-09T16:08:40+01:00
summary:
gh-143191: Use _PyOS_MIN_STACK_SIZE in _thread.stack_size() (#143601)
The stack size must be at least _PyOS_MIN_STACK_SIZE+SYSTEM_PAGE_SIZE
bytes.
files:
A Misc/NEWS.d/next/Library/2026-01-09-13-07-22.gh-issue-143191.PPR_vW.rst
M Lib/test/test_thread.py
M Modules/_threadmodule.c
diff --git a/Lib/test/test_thread.py b/Lib/test/test_thread.py
index d94e04250c9307..ac924728febc99 100644
--- a/Lib/test/test_thread.py
+++ b/Lib/test/test_thread.py
@@ -76,6 +76,14 @@ def test_stack_size(self):
thread.stack_size(0)
self.assertEqual(thread.stack_size(), 0, "stack_size not reset to
default")
+ with self.assertRaises(ValueError):
+ # 123 bytes is too small
+ thread.stack_size(123)
+
+ with self.assertRaises(ValueError):
+ # size must be positive
+ thread.stack_size(-4096)
+
@unittest.skipIf(os.name not in ("nt", "posix"), 'test meant for nt and
posix')
def test_nt_and_posix_stack_size(self):
try:
diff --git
a/Misc/NEWS.d/next/Library/2026-01-09-13-07-22.gh-issue-143191.PPR_vW.rst
b/Misc/NEWS.d/next/Library/2026-01-09-13-07-22.gh-issue-143191.PPR_vW.rst
new file mode 100644
index 00000000000000..507b58362bec97
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-01-09-13-07-22.gh-issue-143191.PPR_vW.rst
@@ -0,0 +1,2 @@
+:func:`_thread.stack_size` now raises :exc:`ValueError` if the stack size is
+too small. Patch by Victor Stinner.
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index cc8277c5783858..73eff27343618c 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -2200,9 +2200,10 @@ thread_stack_size(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "|n:stack_size", &new_size))
return NULL;
- if (new_size < 0) {
- PyErr_SetString(PyExc_ValueError,
- "size must be 0 or a positive value");
+ Py_ssize_t min_size = _PyOS_MIN_STACK_SIZE + SYSTEM_PAGE_SIZE;
+ if (new_size != 0 && new_size < min_size) {
+ PyErr_Format(PyExc_ValueError,
+ "size must be at least %zi bytes", min_size);
return NULL;
}
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]