What is the hard recursion limit for Linux, Mac and Windows?

前端 未结 2 1710
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 07:03

Python\'s sys module provides a function setrecursionlimit that lets you change Python\'s maximum recursion limit. The docs say:

2条回答
  •  北海茫月
    2020-11-30 07:54

    You shouldn't overuse recursive calls in CPython. It has not tail optimization, the function calls use a lot of memory and processing time. Those limits might not apply to other implementations, it's not in the blueprints.

    In CPython, recursion is fine for traversing data structures (where a limit of 1000 should be enough for everybody) but not for algorithms. If I were to implement, say, graph related algorithms and hit the recursion limit, I would either implement my own stack and use iterations, or look for libraries implemented in C/C++/whatever before raising the limit by hand.

提交回复
热议问题