当前位置:网站首页>[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()边栏推荐
- Selenium element interaction
- PXE network
- Unity script API - time class
- .Net 应用考虑x64生成
- Unity脚本API—GameObject游戏对象、Object 对象
- What is the future of the booming intelligent Internet of things (aiot) in recent years?
- 数据湖治理:优势、挑战和入门
- How to save the contents of div as an image- How to save the contents of a div as a image?
- 深入JS中几种数据类型的解构赋值细节
- Logstash~Logstash配置(logstash.yml)详解
猜你喜欢

MySQL learning notes - data type (numeric type)

Game theory

The 17 year growth route of Zhang Liang, an open source person, can only be adhered to if he loves it

Will the memory of ParticleSystem be affected by maxparticles

Actual combat | use composite material 3 in application
![[native JS] optimized text rotation effect](/img/50/3c09f223e821c14e7e9e0fb47622b6.jpg)
[native JS] optimized text rotation effect

MYSQL索引优化

Live broadcast preview | PostgreSQL kernel Interpretation Series II: PostgreSQL architecture

What should ABAP do when it calls a third-party API and encounters garbled code?

How did the beyond concert 31 years ago get super clean and repaired?
随机推荐
Usage of database functions "recommended collection"
Object distance measurement of stereo vision
[North Asia data recovery] data recovery case of database data loss caused by HP DL380 server RAID disk failure
Unity脚本API—Component组件
LeetCode 58. Length of the last word
Intranet penetrating FRP: hidden communication tunnel technology
MySQL federated primary key_ MySQL creates a federated primary key [easy to understand]
Unity script API - time class
华为云数据库DDS产品深度赋能
Logstash~Logstash配置(logstash.yml)详解
MySQL index optimization
[hcie TAC] question 5 - 1
LeetCode 1184. 公交站间的距离 ---vector顺逆时针
数据库函数的用法「建议收藏」
LeetCode 35. 搜索插入位置 —vector遍历(O(logn)和O(n)的写法---二分查找法)
Stew in disorder
MySQL - MySQL adds self incrementing IDs to existing data tables
Review of Weibo hot search in 2021 and analysis of hot search in the beginning of the year
LeetCode 58. 最后一个单词的长度
Hexadecimal form