Skip to content

Commit 8399641

Browse files
bpo-18049: Sync thread stack size to main thread size on macOS (GH-14748)
This changeset increases the default size of the stack for threads on macOS to the size of the stack of the main thread and reenables the relevant recursion test. (cherry picked from commit 1a057ba) Co-authored-by: Ronald Oussoren <[email protected]>
1 parent dcc53eb commit 8399641

File tree

5 files changed

+9
-3
lines changed

5 files changed

+9
-3
lines changed

Lib/test/test_threading.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,8 +1049,6 @@ def test_releasing_unacquired_lock(self):
10491049
lock = threading.Lock()
10501050
self.assertRaises(RuntimeError, lock.release)
10511051

1052-
@unittest.skipUnless(sys.platform == 'darwin' and test.support.python_is_optimized(),
1053-
'test macosx problem')
10541052
def test_recursion_limit(self):
10551053
# Issue 9670
10561054
# test that excessive recursion within a non-main thread causes
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Increase the default stack size of threads from 5MB to 16MB on macOS, to
2+
match the stack size of the main thread. This avoids crashes on deep recursion
3+
in threads.

Python/thread_pthread.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
*/
4141
#if defined(__APPLE__) && defined(THREAD_STACK_SIZE) && THREAD_STACK_SIZE == 0
4242
#undef THREAD_STACK_SIZE
43-
#define THREAD_STACK_SIZE 0x500000
43+
/* Note: This matches the value of -Wl,-stack_size in configure.ac */
44+
#define THREAD_STACK_SIZE 0x1000000
4445
#endif
4546
#if defined(__FreeBSD__) && defined(THREAD_STACK_SIZE) && THREAD_STACK_SIZE == 0
4647
#undef THREAD_STACK_SIZE

configure

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9542,6 +9542,8 @@ then
95429542
# Issue #18075: the default maximum stack size (8MBytes) is too
95439543
# small for the default recursion limit. Increase the stack size
95449544
# to ensure that tests don't crash
9545+
# Note: This matches the value of THREAD_STACK_SIZE in
9546+
# thread_pthread.h
95459547
LINKFORSHARED="-Wl,-stack_size,1000000 $LINKFORSHARED"
95469548

95479549
if test "$enable_framework"

configure.ac

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2694,6 +2694,8 @@ then
26942694
# Issue #18075: the default maximum stack size (8MBytes) is too
26952695
# small for the default recursion limit. Increase the stack size
26962696
# to ensure that tests don't crash
2697+
# Note: This matches the value of THREAD_STACK_SIZE in
2698+
# thread_pthread.h
26972699
LINKFORSHARED="-Wl,-stack_size,1000000 $LINKFORSHARED"
26982700

26992701
if test "$enable_framework"

0 commit comments

Comments
 (0)