Wednesday, 16 December 2015

Python: Set stack size for a thread

‘threading.stack_size([size])’ method is used to set and set stack size for a thread. Size argument is optional.

Size
Description
0
Use platform dependent size. If you don’t specify the size, then 0 is used by default.
>0
Minimum size should be 32,768 (32 KiB). It is recommended that size should be multiple of 4096.

If the specified stack size is invalid, a ValueError is raised and the stack size is unmodified. If changing the thread stack size is unsupported, a RuntimeError is raised.


MyThread.py
import threading

print("Current stack size ", threading.stack_size())
threading.stack_size(32768 )
print("Current stack size ", threading.stack_size())

$ python3 MyThread.py 
Current stack size  0
Current stack size  32768



Previous                                                 Next                                                 Home

No comments:

Post a Comment