How to increase stack size in python

I have a python program that uses a custom DLL. This dll failed because of. This overflow is not due to a bad recursive function, but for large distributions on the stack using alloca ().

I want to increase the size of the stack to get rid of this error. Is there any way to do this?

+7
source share
4 answers

An AFAIK program can resize the stack of new threads or processes (for example, CreateThread ). Since Python (and the Win32 API for Python) does not reveal this functionality, it is better to replace the stack allocation with a bunch of memory. Or is there a specific reason to use the stack? If you really need to use it alloca, you may need to create a separate thread to execute the DLL code (which, in my opinion, is too large).

EDIT: Correction. Python allows you to set the stack size when creating new threads (see thread.stack_size )

+2
source

python . , , DLL .

+6

, , , , , , . python 3.5 Windows 10 x64 , ( 993). , , , , Python.

import sys
import threading

class SomeCallable:
    def __call__(self):
        try:
            self.recurse(99900)
        except RecursionError:
            print("Booh!")
        else:
            print("Hurray!")
    def recurse(self, n):
        if n > 0:
            self.recurse(n-1)

SomeCallable()() # recurse in current thread

# recurse in greedy thread
sys.setrecursionlimit(100000)
threading.stack_size(0x2000000)
t = threading.Thread(target=SomeCallable())
t.start()
t.join()
+4

Functions in the dll cannot control the stack size available when they are executed (unless you create new threads under the control of your library).

If the dll is normal, then you cannot allocate a heap, not a stack (or statically allocate if necessary) and stop the problem this way?

+2
source

All Articles