I need to increase the recursion limit/stack size for a Python program (just a CP problem, not production code). I've found several ways to do this (e.g. this and this):
import resource, sys
resource.setrlimit(resource.RLIMIT_STACK, (2**29,-1))
sys.setrecursionlimit(10**6)
or
import sys
import threading
threading.stack_size(67108864) # 64MB stack
sys.setrecursionlimit(2 ** 20)
thread = threading.Thread(target=main)
thread.start()
What's the difference between the two methods and which one should I prefer?