Skip to content

Commit 274f835

Browse files
committed
Set the QThreadPool stacksize to match python expectations.
1 parent af83d92 commit 274f835

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/qasync/__init__.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,19 @@ def __enter__(self, *args):
202202
def __exit__(self, *args):
203203
self.shutdown()
204204

205+
@staticmethod
206+
def compute_stack_size():
207+
# Match cpython/Python/thread_pthread.h
208+
if sys.platform.startswith("darwin"):
209+
stack_size = 16 * 2**20
210+
elif sys.platform.startswith("freebsd"):
211+
stack_size = 4 * 2**20
212+
elif sys.platform.startswith("aix"):
213+
stack_size = 2 * 2**20
214+
else:
215+
stack_size = None
216+
return stack_size
217+
205218

206219
@with_logger
207220
class QThreadExecutor(QThreadExecutorBase):
@@ -222,13 +235,7 @@ def __init__(self, max_workers=10, stack_size=None):
222235
self.__max_workers = max_workers
223236
self.__queue = Queue()
224237
if stack_size is None:
225-
# Match cpython/Python/thread_pthread.h
226-
if sys.platform.startswith("darwin"):
227-
stack_size = 16 * 2**20
228-
elif sys.platform.startswith("freebsd"):
229-
stack_size = 4 * 2**20
230-
elif sys.platform.startswith("aix"):
231-
stack_size = 2 * 2**20
238+
stack_size = self.compute_stack_size()
232239
self.__workers = [
233240
_QThreadWorker(self.__queue, i + 1, stack_size) for i in range(max_workers)
234241
]

tests/test_qthreadexec.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ def executor(request):
4646
def get_executor(request):
4747
if request.param is qasync.QThreadPoolExecutor:
4848
pool = qasync.QtCore.QThreadPool()
49+
stack_size = qasync.QThreadExecutorBase.compute_stack_size()
50+
if stack_size is not None:
51+
pool.setStackSize(stack_size)
4952
pool.setMaxThreadCount(5)
5053
return request.param(pool)
5154
else:

0 commit comments

Comments
 (0)