[HELP][Question] Python programs with huge recursion depth.
Difference between en1 and en2, changed 2 character(s)
So I was trying to solve few graph questions and during dfs if the graph has nodes and edges of magnitude  ~10**5 python was giving run time or sigsev error even if the recursion limit is set explicitly using sys.setrecursionlimit(10**6). ↵
After googling about the stack size issues in pyhton I came across a [Stackoverflow blog](https://stackoverflow.com/questions/5061582/setting-stacksize-in-a-python-script).↵

The second answer using the resource module was helpful ↵

~~~~~↵
    import resource, sys↵
    resource.setrlimit(resource.RLIMIT_STACK, (2**29,-1))↵
    sys.setrecursionlimit(10**6)↵
~~~~~↵


and I was able to avoid the recursion depth issue on [this question](https://www.hackerearth.com/practice/algorithms/graphs/articulation-points-and-bridges/practice-problems/algorithm/sg-and-graphs/) on hackerearth. ↵

But the problem is **resource module** is not available on Codeforces. Even though its available on Codechef as well as hackerearth.↵

So I tried another module threading ↵

~~~~~↵
    sys.setrecursionlimit(10**6)↵
    threading.stack_size(10**8)↵
    t = threading.Thread(target=main)↵
    t.start()↵
    t.join()↵
~~~~~↵


and its available here in codeforces as well but the issue is the memory consumption is huge if we use threading module and it sometimes even causes memory lmiit exceeded error.↵

The question I mentioned above on articulation point and bridges. ↵

[Solution using Resource module.](https://www.hackerearth.com/submission/23227365/)↵

[Solution using Threading module.](https://www.hackerearth.com/submission/23227954/)↵
You can see the second test case threw memory limit exceeded.↵

So are the Codeforces machines running a windows system as resource module is not avilable for windows according to an old comment on the stackoverflow blow. ↵

And if you are python programmer what else do you use for programs with huge recursion depth.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English H4wk3ye 2019-01-22 14:27:23 51
en2 English H4wk3ye 2019-01-22 14:10:56 2 Tiny change: 'helpful \n~~~~~\n ' -> 'helpful \n\n~~~~~\n '
en1 English H4wk3ye 2019-01-22 14:10:33 1964 Initial revision (published)