当前位置:网站首页>[Previous line repeated 995 more times]RecursionError: maximum recursion depth exceeded
[Previous line repeated 995 more times]RecursionError: maximum recursion depth exceeded
2022-07-04 16:11:00 【Liluoxiao】
reason : Recursion depth exceeded
solve :
import sys
sys.setrecursionlimit(100000)
Encountered new problems :Process finished with exit code -1073741571 (0xC00000FD)
reason : Stack overflow
Usually windows The default stack size is 1024bytes
solve :
1. It may be that the value of the local variable is too large , Change it to a global variable ( Pay attention to Out of function use global Statement )
2. Tail recursion :Python The interpreter is in a function call , A stack frame will be used to save the information of the currently called function , Such as input parameters 、 Return value space 、 Temporary storage space used to evaluate expressions 、 State information and output parameters saved during function call . So in recursive calls , Such unexecuted functions will occupy a large number of stack frames layer by layer . If you put the recursive call to the last step of function execution , Then finish this step , The stack frame of this function will be released , The new stack frame of the calling function will replace the previous stack frame , So no matter how many times the depth of the call is , Will only occupy a stack frame , Then there will be no stack overflow problem . This is tail recursion .
The key : The precondition is that nothing will be executed after the call , Therefore, what needs to be passed must be passed through parameter design in advance
for example : and
The first is to multiply after each call n, there res It plays the same role , Due to tail recursion, the stack frame of each layer should be released , So pass res As a multiplication process
3. Modify stack heap size :
python of use threading To carry out :
if __name__ == '__main__':
threading.stack_size(200000000)
thread = threading.Thread(target=your_code)
thread.start()
边栏推荐
- Unity script API - GameObject game object, object object
- Quelles sont les perspectives de l'Internet intelligent des objets (aiot) qui a explosé ces dernières années?
- 2022年九大CIO趨勢和優先事項
- Unity script API - time class
- 基于MAX31865的温度控制系统
- Understand Alibaba cloud's secret weapon "dragon architecture" in the article "science popularization talent"
- Unity预制件Prefab Day04
- QT graphical view frame: element movement
- lnx 高效搜索引擎、FastDeploy 推理部署工具箱、AI前沿论文 | ShowMeAI资讯日报 #07.04
- 压力、焦虑还是抑郁? 正确诊断再治疗
猜你喜欢
Talking about Net core how to use efcore to inject multiple instances of a context annotation type for connecting to the master-slave database
Dry goods | fMRI standard reporting guidelines are fresh, come and increase your knowledge
In today's highly integrated chips, most of them are CMOS devices
2022年九大CIO趨勢和優先事項
The 17 year growth route of Zhang Liang, an open source person, can only be adhered to if he loves it
Live broadcast preview | PostgreSQL kernel Interpretation Series II: PostgreSQL architecture
Function test - knowledge points and common interview questions
Working group and domain analysis of Intranet
2022年九大CIO趋势和优先事项
[hcie TAC] question 5 - 1
随机推荐
The per capita savings of major cities in China have been released. Have you reached the standard?
Live broadcast preview | PostgreSQL kernel Interpretation Series II: PostgreSQL architecture
Quelles sont les perspectives de l'Internet intelligent des objets (aiot) qui a explosé ces dernières années?
MYSQL索引优化
What should ABAP do when it calls a third-party API and encounters garbled code?
Move, say goodbye to the past again
Case sharing | integrated construction of data operation and maintenance in the financial industry
Common knowledge of unity Editor Extension
Talking about Net core how to use efcore to inject multiple instances of a context annotation type for connecting to the master-slave database
Introduction of text mining tools [easy to understand]
中国主要城市人均存款出炉,你达标了吗?
Selenium browser (2)
這幾年爆火的智能物聯網(AIoT),到底前景如何?
An article learns variables in go language
Data Lake Governance: advantages, challenges and entry
js平铺数据查找叶子节点
165 webmaster online toolbox website source code / hare online tool system v2.2.7 Chinese version
Width accuracy
LeetCode 35. 搜索插入位置 —vector遍历(O(logn)和O(n)的写法---二分查找法)
华为云数据库DDS产品深度赋能