Message310245
CPython pushes a frame on the thread's stack for every Python frame. By default in Windows Python the thread's stack is allowed to grow up to about 2 MB. On Linux the default limit is 8 MB, but a higher limit can be set via `ulimit -s`. After the stack is full, pushing another value will crash the process due to a stack overflow. Windows raises a STATUS_STACK_OVERFLOW (0xC00000FD) exception. Linux raises a SIGSEGV signal (segmentation fault).
The default interpreter recursion limit of 1,000 is set to raise a Python RecursionError well before you'd see a hard crash from a stack overflow. If we ballpark a C stack frame at about 1 KB in 64-bit Python, then the default stack size on Windows should support a recursion limit of about 2,000. For a recursion limit of 100,000, I would estimate a 100 MB stack size.
You can call threading.stack_size(size_in_bytes) to reserve a larger stack size for new threads. However, in Python code it's better to rewrite such deeply recursive cases to use loops instead. |
|
Date |
User |
Action |
Args |
2018-01-18 15:05:20 | eryksun | set | recipients:
+ eryksun, paul.moore, tim.golden, zach.ware, steve.dower, Vasyl Kolomiets |
2018-01-18 15:05:20 | eryksun | set | messageid: <1516287920.01.0.467229070634.issue32570@psf.upfronthosting.co.za> |
2018-01-18 15:05:19 | eryksun | link | issue32570 messages |
2018-01-18 15:05:19 | eryksun | create | |
|